This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
65 lines (62 loc) · 1.84 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
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const SriPlugin = require('webpack-subresource-integrity');
let plugins = [
new CopyWebpackPlugin({
patterns: [
{
from: 'src/style.css',
to: 'style.css'
}
]
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
inject: 'body',
minify: (process.env.NODE_ENV === 'production') ? {
collapseWhitespace: true,
conservativeCollapse: true
} : false,
hash: false,
cache: false,
showErrors: false
}),
new HtmlWebpackTagsPlugin({ tags: ['style.css'], append: true, useHash: false })
];
if (process.env.NODE_ENV === 'production') {
plugins.push(new UglifyJSPlugin({
uglifyOptions: {
mangle: true,
sourceMap: false,
compress: true
}
}));
plugins.push(new SriPlugin({
hashFuncNames: ['sha256', 'sha384'],
enabled: process.env.NODE_ENV === 'production'
}));
}
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, (process.env.OUT_DIR) ? process.env.OUT_DIR : './build'),
filename: (process.env.NODE_ENV === 'production') ? 'bundle.[hash].js' : 'bundle.js',
crossOriginLoading: 'anonymous'
},
plugins: plugins,
module: {
rules: [{
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
}
}