-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
115 lines (108 loc) · 2.57 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
113
114
115
const path = require('path');
const merge = require('webpack-merge');
const validate = require('webpack-validator');
const parts = require('./libs/parts');
const TARGET = process.env.npm_lifecycle_event;
const ENABLE_POLLING = process.env.ENABLE_POLLING;
const PATHS = {
app: path.join(__dirname, 'app'),
style: [
path.join(__dirname, 'app', 'main.css')
],
build: path.join(__dirname, 'build'),
test: path.join(__dirname, 'tests')
};
process.env.BABEL_ENV = TARGET;
const common = merge(
{
// Entry accepts a path or an object of entries.
// We'll be using the latter form given it's
// convenient with more complex configurations.
entry: {
app: PATHS.app
},
output: {
path: PATHS.build,
filename: '[name].js',
// TODO: Set publicPath to match your GitHub project name
// E.g., '/kanban-demo/'. Webpack will alter asset paths
// based on this. You can even use an absolute path here
// or even point to a CDN.
publicPath: '/kanban-demo/'
},
resolve: {
extensions: ['', '.js', '.jsx']
}
},
parts.indexTemplate({
title: 'Kanban demo',
appMountId: 'app'
}),
parts.loadJSX(PATHS.app),
parts.lintJSX(PATHS.app)
);
var config;
// Detect how npm is run and branch based on that
switch(TARGET) {
case 'build':
case 'stats':
config = merge(
common,
{
devtool: 'source-map',
entry: {
style: PATHS.style
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js'
}
},
parts.clean(PATHS.build),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.extractBundle({
name: 'vendor',
entries: ['react', 'react-dom']
}),
parts.minify(),
parts.extractCSS(PATHS.style)
);
break;
case 'test':
case 'test:tdd':
config = merge(
common,
{
devtool: 'inline-source-map'
},
parts.loadIsparta(PATHS.app),
parts.loadJSX(PATHS.test)
);
break;
default:
config = merge(
common,
{
devtool: 'eval-source-map',
entry: {
style: PATHS.style
}
},
parts.setupCSS(PATHS.style),
parts.devServer({
// Customize host/port here if needed
host: process.env.HOST,
port: process.env.PORT,
poll: ENABLE_POLLING
}),
parts.enableReactPerformanceTools(),
parts.npmInstall()
);
}
module.exports = validate(config, {
quiet: true
});