Skip to content

Commit

Permalink
Replace Parcel with Webpack 5
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Sep 11, 2020
1 parent 99b0460 commit 21eb2c1
Show file tree
Hide file tree
Showing 4 changed files with 2,476 additions and 2,561 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "dist/esm/index.js",
"source": "src/index.js",
"sideEffects": [
"*.css"
"*.css",
"*.less"
],
"workspaces": [
".",
Expand Down
18 changes: 15 additions & 3 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A test page for React-Calendar.",
"private": true,
"scripts": {
"build": "parcel build index.html --public-url ./",
"start": "parcel index.html"
"build": "NODE_ENV=production webpack",
"start": "NODE_ENV=development webpack-dev-server"
},
"author": {
"name": "Wojciech Maj",
Expand All @@ -24,6 +24,18 @@
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"parcel-bundler": "^1.12.4"
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.1",
"babel-loader": "^8.0.0",
"css-loader": "^4.3.0",
"file-loader": "^6.1.0",
"html-webpack-plugin": "^4.4.0",
"less": "^3.12.0",
"less-loader": "^7.0.0",
"mini-css-extract-plugin": "^0.11.0",
"react-refresh": "^0.8.3",
"style-loader": "^1.2.0",
"webpack": "^5.0.0-0",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.11.0"
}
}
80 changes: 80 additions & 0 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = !isProduction;

module.exports = {
mode: isProduction ? 'production' : 'development',
bail: isProduction,
context: path.join(__dirname),
entry: {
src: './index.jsx',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash:8].js',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
babelrcRoots: ['.', '../'],
plugins: [isDevelopment && 'react-refresh/babel'].filter(Boolean),
},
},
],
},
{
test: /\.less$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'less-loader',
],
},
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
].filter(Boolean),
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
}),
isProduction && new MiniCssExtractPlugin({
filename: '[name].[chunkhash:8].css',
chunkFilename: '[name].[chunkhash:8].css',
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
optimization: {
moduleIds: 'named',
},
stats: {
assetsSort: '!size',
entrypoints: false,
},
devServer: {
compress: true,
historyApiFallback: true, // respond to 404s with index.html
host: 'localhost',
hot: true, // enable HMR on the server
port: 3000,
},
};
Loading

0 comments on commit 21eb2c1

Please sign in to comment.