抽取公共代码
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let webpack = require('webpack');
module.exports = {
optimization: {
splitChunks: {
cacheGroups: {
common: {
chunks: "initial",
minSize: 0,
minChunks: 2,
},
vendor: {
priority: 1,
test: /node_modules/,
chunks: "initial",
minSize: 0,
minChunks: 2,
}
}
}
},
entry: {
index: './src/index.js',
other: './src/other.js',
},
mode:'production',
devServer: {
port: 3000,
open: true,
contentBase: './dist',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: path.resolve('./src/'),
use: [{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react'
]
}
}]
}
]
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.IgnorePlugin(/\.\/locale/, /moment/),
new HtmlWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
}),
]
};