Skip to content

Commit

Permalink
Specify webpack mode production in build script (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
avidit authored Oct 5, 2022
1 parent 82f41e2 commit d241443
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
/dist

# misc
.DS_Store
Expand All @@ -21,4 +22,3 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/dist/build
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"react": "^18.2.0",
"react-bootstrap": "^2.5.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1"
"react-scripts": "5.0.1"
},
"scripts": {
"build": "webpack --config webpack.config.js",
"scripts": {
"start": "webpack serve --config webpack.config.js",
"build": "webpack --config webpack.config.js --mode=production",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "webpack serve --config webpack.config.js"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
Expand All @@ -38,4 +38,4 @@
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}
}
81 changes: 41 additions & 40 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@ const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = (env) => {
return {
mode: 'development',
entry: {
app: './src/index.js',
module.exports = () => {
return {
mode: 'development',
entry: {
app: './src/index.js',
},
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.bundle.js',
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
output: {
path: path.join(__dirname, '/dist/build'),
filename: 'index.bundle.js',
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
},
}),
]
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html'
})
]
};
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
},
}),
]
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html'
})
]
};
};

0 comments on commit d241443

Please sign in to comment.