-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
89 lines (79 loc) · 2.36 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
"use strict";
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const validate = require('webpack-validator');
const PATHS = require('./configs/Paths');
const parts = require('./configs/parts');
const pkg = require('./package.json');
const HtmlWebpackPlugin = require('html-webpack-plugin');
let config,
npmCommand = process.env.npm_lifecycle_event;
let entryPoints = {};
PATHS.entryPoints.forEach(function (entryPoint) {
entryPoints[entryPoint.title] = [path.resolve(PATHS.src + PATHS.js + entryPoint.folder)];
});
const common = {
entry: entryPoints,
resolve: {
extensions: ['', '.js', '.jsx']
},
plugins: [
new HtmlWebpackPlugin({
template: PATHS.src + '/index.html',
filename: '../index.html'
})
]
};
switch (npmCommand) {
case 'build':
config = merge(
common,
{
devtool: 'source-map',
output: {
path: PATHS.dist,
filename: '.' + PATHS.js + '/[name].[chunkhash].js',
// This is used for require.ensure. The setup
// will work without but this is useful to set.
chunkFilename: '[chunkhash].js'
}
},
parts.clean(PATHS.dist),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.extractBundle({
name: 'vendor',
entries: Object.keys(pkg.dependencies) //['react', 'react-dom']
}),
parts.fonts([PATHS.fonts]),
parts.json(),
parts.extractCSS(PATHS.css),
parts.purifyCSS([PATHS.src]),
parts.babel([PATHS.src]),
parts.minify()
);
break;
default:
config = merge(
common,
{
devtool: 'eval-source-map'
},
parts.setupSass(PATHS.sass),
parts.devServer({
host: PATHS.host,
port: PATHS.port
}),
parts.babelHot([PATHS.src]),
parts.fonts([PATHS.fonts]),
parts.json(),
parts.openBrowser(PATHS.projectUrl)
);
break;
}
module.exports = validate(config, {
quiet: true
});