-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
95 lines (93 loc) · 3.07 KB
/
Copy pathwebpack.config.js
File metadata and controls
95 lines (93 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const HTMLWebPackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const AsyncChunkNames = require('webpack-async-chunk-names-plugin');
const Autoprefixer = require('autoprefixer');
const path = require('path');
const htmlPlugin = new HTMLWebPackPlugin({
template: './src/index.html',
filename: './index.html'
});
module.exports = (env, options) => ({
entry: { main: './src/index.js' },
output: {
path: path.resolve(__dirname, 'dist'),
filename: options.mode === 'production' ? '[name].[hash].js' : '[name].js'
},
// optimization: {
// runtimeChunk: 'single',
// splitChunks: {
// cacheGroups: {
// default: false,
// vendors: false,
// // vendor chunk
// vendor: {
// // sync + async chunks
// chunks: 'all',
// // import file path containing node_modules
// test: /node_modules/
// },
// common: {
// name: 'common',
// minChunks: 2,
// chunks: 'async',
// priority: 10,
// reuseExistingChunk: true,
// enforce: true
// }
// }
// }
// },
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
},
{
test: /\.(css|sass|scss)$/,
use: [
options.mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{ loader: 'css-loader', options: { importLoaders: 2, sourceMap: true } },
{
loader: 'postcss-loader',
options: { plugins: () => [Autoprefixer], sourceMap: true }
},
{ loader: 'sass-loader', options: { sourceMap: true } }
]
},
{
test: /\.(jpg|png|svg|gif)$/,
loader: 'file-loader',
options: {
name: '[path][name].[hash].[ext]'
}
}
]
},
plugins: [
new CleanWebpackPlugin('dist', {}),
new MiniCssExtractPlugin({
filename: 'style.[hash].css'
}),
new AsyncChunkNames(),
htmlPlugin,
new WebpackMd5Hash()
],
devtool: options.mode === 'production' ? false : 'cheap-module-eval-source-map',
devServer:
options.mode === 'production'
? {}
: {
historyApiFallback: true
}
});