-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.js
92 lines (86 loc) · 2.38 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
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var glob = require('glob');
let PurifyCSSPlugin = require('purifycss-webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin')
var inProduction = (process.env.NODE_ENV === 'production');
var HWPConfig = new HtmlWebpackPlugin({
template: __dirname + "/index.html",
file: "index.html",
inject: "body"
});
module.exports = {
entry: {
app: [
'./src/main.js',
'./src/main.scss'
]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].[chunkhash].js'
},
module: {
rules: [{
test: /\.s[ac]ss$/,
use: ExtractTextPlugin.extract({
use: ['css-loader', 'sass-loader'],
fallback: 'style-loader'
})
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'img/[name].[hash].[ext]'
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: [
["es2015", {
modules: false
}]
]
}
},
]
},
plugins: [
HWPConfig,
new CleanWebpackPlugin(['dist'], {
root: __dirname,
verbose: true,
dry: false
}),
new ExtractTextPlugin('[name].css'),
new PurifyCSSPlugin({
paths: glob.sync(path.join(__dirname, 'index.html')),
minimize: inProduction
}),
new webpack.LoaderOptionsPlugin({
minimize: inProduction
}),
]
};
if (inProduction) {
module.exports.plugins.push(
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true
}
})
)
}