-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
95 lines (91 loc) · 2.85 KB
/
webpack.config.js
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 path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// Set mode
const argv = require('yargs').argv;
const devMode = argv.mode !== 'production';
module.exports = {
mode: argv.mode,
devtool: devMode ? 'source-map' : false,
entry: {
index: './src/index.js',
},
output: {
path: path.resolve(__dirname, 'docs'),
filename: '[name].bundle.js',
clean: true,
},
module: {
rules: [
{
test: /\.(s(a|c)ss)$/,
use: [
// In dev create `<style>` nodes from JS string.
// In production generate css files
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
{
loader: 'sass-loader', // compiles Sass to CSS
options: {
sassOptions: {
includePaths: ['./node_modules/normalize.css'],
},
},
},
],
},
],
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
},
},
},
},
},
plugins: [
new CopyWebpackPlugin({
patterns: [{ from: 'src/assets', to: './assets' }],
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
// favicon: `src/favicon.ico`,
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
performance: {
maxEntrypointSize: 1024000,
maxAssetSize: 1024000,
},
devServer: {
static: './docs',
hot: true,
compress: true,
client: {
progress: true,
overlay: {
errors: true,
warnings: false,
},
},
},
};