Skip to content

Commit a73c95a

Browse files
committed
config: build mode => mode by cross-env, devtool
1 parent c75f0fa commit a73c95a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "webpack.config.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "webpack",
9-
"build": "webpack --mode production"
8+
"start": "cross-env NODE_ENV=development webpack",
9+
"build": "cross-env NODE_ENV=production webpack --mode production"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -29,6 +29,7 @@
2929
"@babel/preset-env": "^7.22.10",
3030
"babel-loader": "^9.1.3",
3131
"copy-webpack-plugin": "^11.0.0",
32+
"cross-env": "^7.0.3",
3233
"css-loader": "^6.8.1",
3334
"html-webpack-plugin": "^5.5.3",
3435
"mini-css-extract-plugin": "^2.7.6",

webpack.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
55
const webpack = require('webpack');
66

7+
const isProd = process.env.NODE_ENV === 'production';
8+
const isDev = !isProd;
9+
710
module.exports = {
811
context: path.resolve(__dirname, 'src'),
9-
mode: 'development',
12+
mode: isDev ? 'development' : 'production',
1013
entry: './index.js',
1114
output: {
1215
filename: 'bundle.[contenthash].js',
@@ -42,6 +45,10 @@ module.exports = {
4245
new webpack.ProgressPlugin(),
4346
new HtmlWebpackPlugin({
4447
template: 'index.html',
48+
minify: {
49+
removeComments: isProd,
50+
collapseWhitespace: isProd,
51+
},
4552
}),
4653
new CopyWebpackPlugin({
4754
patterns: [{ from: 'favicon.ico', to: path.resolve(__dirname, 'dist') }],
@@ -50,4 +57,5 @@ module.exports = {
5057
filename: 'bundle.[contenthash].css',
5158
}),
5259
],
60+
devtool: isDev ? 'source-map' : false,
5361
};

0 commit comments

Comments
 (0)