This commit is contained in:
Daniel Ledda
2020-11-18 22:51:30 +01:00
parent 841861ee87
commit 4b0c5bc9ab
8 changed files with 100 additions and 78 deletions

View File

@@ -1,34 +1,11 @@
const path = require('path');
const webpack = require('webpack');
/*
* SplitChunksPlugin is enabled by default and replaced
* deprecated CommonsChunkPlugin. It automatically identifies modules which
* should be splitted of chunk by heuristics using module duplication count and
* module category (i. e. node_modules). And splits the chunks…
*
* It is safe to remove "splitChunks" from the generated configuration
* and was added as an educational example.
*
* https://webpack.js.org/plugins/split-chunks-plugin/
*
*/
/*
* We've enabled TerserPlugin for you! This minifies your app
* in order to load faster and run less javascript.
*
* https://github.com/webpack-contrib/terser-webpack-plugin
*
*/
const config = require('./src/config.json');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
mode: 'production',
const webpackConfig = {
mode: 'development',
entry: './src/main.ts',
plugins: [new webpack.ProgressPlugin()],
@@ -45,7 +22,6 @@ module.exports = {
loader: "style-loader"
}, {
loader: "css-loader",
options: {
sourceMap: true
}
@@ -57,29 +33,34 @@ module.exports = {
extensions: ['.tsx', '.ts', '.js']
},
optimization: {
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/
}
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: false
}
},
devServer: {
contentBase: path.join(__dirname, "dist/"),
contentBasePublicPath: "/static/",
contentBasePublicPath: "/",
port: 3000,
publicPath: "http://localhost:3000/",
hotOnly: true
},
}
};
if (!config.development) {
webpackConfig.optimization = {
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/
}
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: false
}
};
webpackConfig.mode = 'production';
}
module.exports = {...webpackConfig};