-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
87 lines (83 loc) · 2.05 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const pug = require('./webpack/pug');
const devserver = require('./webpack/devserver');
const sass = require('./webpack/sass');
const extractCSS = require('./webpack/css.extract');
const css = require('./webpack/css');
const webpack = require('webpack');
const sourceMap = require('./webpack/sourceMap');
const lintJS = require('./webpack/js.lint');
const lintCSS = require('./webpack/sass.lint');
const images = require('./webpack/images');
const babel = require('./webpack/babel');
const favicon = require('./webpack/favicon');
const PATHS = {
source: path.join(__dirname, 'source'),
build: path.join(__dirname, 'build'),
};
const common = merge([
{
entry: {
'index': PATHS.source + '/pages/index/index.js',
'blog': PATHS.source + '/pages/blog/blog.js',
},
output: {
path: PATHS.build,
filename: './js/[name].js',
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
chunks: ['index', 'common'],
template: PATHS.source + '/pages/index/index.pug',
}),
new HtmlWebpackPlugin({
filename: 'blog.html',
chunks: ['blog', 'common'],
emplate: PATHS.source + '/pages/blog/blog.pug',
}),
],
optimization: {
splitChunks: {
cacheGroups: {
'common': {
minChunks: 2,
chunks: 'all',
name: 'common',
priority: 10,
enforce: true,
},
},
},
},
},
pug(),
// lintJS({ paths: PATHS.sources }),
lintCSS(),
images(),
babel(),
]);
module.exports = function(env, argv) {
if (argv.mode === 'production') {
return merge([
common,
extractCSS(),
favicon(),
]);
}
if (argv.mode === 'development') {
return merge([
common,
devserver(),
sass(),
css(),
sourceMap(),
]);
}
};