-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwebpack.config.js
112 lines (96 loc) · 3 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const validate = require('webpack-validator');
const parts = require('./webpack.parts');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const PATHS = {
app: path.join(__dirname, 'app', 'static', 'src'),
style: path.join(__dirname, 'app', 'static', 'src', 'styles', 'main.scss'),
build: path.join(__dirname, 'app', 'build'),
dev: path.join(__dirname, 'app', 'static', 'dev')
};
const TARGET = process.argv.slice(2)[0].includes('build') ? 'BUILD' : 'DEV'; // webpack --build || webpack --dev
var config;
switch(TARGET) {
case 'BUILD':
config = merge({
devtool:'source-map',
cache: false,
entry: {
app: PATHS.app,
style: PATHS.style
},
output: {
path: PATHS.build,
publicPath: '/',
filename: 'js/[name].[chunkhash].js',
chunkFilename: '[chunkhash].js'
},
plugins: [],
resolve: {
extensions: ['', '.js', '.jsx'],
// alias: {
// 'react': 'react-lite',
// 'react-dom': 'react-lite'
// }
}
},
parts.clean(PATHS.build),
parts.babelLoader(),
parts.staticLoader(TARGET),
parts.copyFiles(PATHS.build),
parts.extractBundle({
name: 'vendor',
entries: ['react', 'react-dom', 'react-redux']
}),
parts.minify(),
parts.extractCSS(PATHS.style, TARGET),
parts.assetsJson()
);
break;
default:
config = merge({
devtool: 'source-map',
watch: true,
cache: true,
entry: {
app: PATHS.app,
style: PATHS.style
},
output: {
path: PATHS.dev,
publicPath: '/',
filename: 'js/[name].js',
},
plugins: [
new CopyWebpackPlugin([
{
from: 'app/static/src/favicon.png',
to: PATHS.dev,
}
])
],
resolve: {
extensions: ['', '.js', '.jsx'],
// alias: {
// 'react': 'react-lite',
// 'react-dom': 'react-lite'
// }
}
},
parts.clean(PATHS.dev),
parts.babelLoader(),
parts.staticLoader(TARGET),
parts.extractBundle({
name: 'vendor',
entries: ['react', 'react-dom', 'react-redux']
}),
parts.extractCSS(PATHS.style, TARGET)
);
break;
}
// Run validator in quiet mode to avoid output in stats
module.exports = validate(config, {
quiet: true
});