-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
100 lines (93 loc) · 2.56 KB
/
webpack.common.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
96
97
98
99
100
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: {
bundle: './app/js/app.js'
},
output: {
path: path.resolve(__dirname, 'build'),
// filename: 'bundle.js'
filename: process.env.NODE_ENV === 'production' ? '[name].[contenthash].js' : '[name].js'
// '[name].[chunkhash].js'
},
plugins: [
new CleanWebpackPlugin(['build/*']),
// bundle CSS together and emit the result into "style.css" file
new MiniCssExtractPlugin({
filename: process.env.NODE_ENV === 'production' ? 'style.[contenthash].css' : 'style.css'
}),
new HtmlWebpackPlugin({
// // template: 'build/index.html',
// template: 'out.html',
template: 'app/index.pug',
inject: 'head',
minify: {
// remove HTML comments on production
removeComments: process.env.NODE_ENV === 'production',
// don't remove HTML comment with build info
ignoreCustomComments: [ /^.*Built from.*$/ ]
}
})
],
module: {
rules: [
{
// ES6 to ES5 with Babel
use: 'babel-loader',
test: /\.js$/,
// disable AMD modules due to problem in jquery.caret
parser: {
amd: false
}
},
{
// pug templates to HTML
// use: [
// {
// // emit HTML files to build folder
// loader: 'file-loader',
// options: {
// // name: '[name].html'
// name: 'out.html'
// }
// },
// {
// loader: 'pug-html-loader',
// options: {
// // pretty output only for dev
// pretty: process.env.NODE_ENV !== 'production'
// }
// }
// ],
use: [
{
loader: 'pug-loader',
options: {
// pretty output only for dev
pretty: process.env.NODE_ENV !== 'production'
}
}
],
test: /\.pug$/
},
{
// bundle CSS, with source maps on dev
use: [
// emit bundled file
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
// minimize on prod
minimize: process.env.NODE_ENV === 'production'
}
}
],
test: /\.css$/
}
]
}
};