forked from cloud-gov/cg-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
105 lines (91 loc) · 2.33 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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PRODUCTION = (process.env.NODE_ENV === 'prod');
const TEST = (process.env.NODE_ENV === 'test');
const CG_STYLE_PATH = process.env.CG_STYLE_PATH;
const CF_SKIN = process.env.CF_SKIN || 'cg';
const srcDir = './static_src';
const compiledDir = './static/assets';
const config = {
bail: false,
entry: [
'babel-polyfill',
`${srcDir}/main.js`
],
output: {
path: path.resolve(compiledDir),
filename: 'bundle.js',
sourceMapFilename: 'bundle.js.map'
},
devtool: PRODUCTION ? 'cheap-source-map' : 'eval-source-map',
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
presets: ['es2015', 'react'],
plugins: ['transform-object-rest-spread', 'transform-runtime']
},
exclude: [
path.resolve(__dirname, 'node_modules')
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},
{
test: /\.(svg|ico|png|gif|jpe?g)$/,
loader: 'url-loader?limit=1024&name=img/[name].[ext]'
},
{ test: /\.(ttf|woff2?|eot)$/,
loader: 'url-loader?limit=1024&name=font/[name].[ext]'
}
]
},
resolve: {
alias: {
'cloudgov-style': 'cloudgov-style',
skin: path.resolve(__dirname, `static_src/skins/${CF_SKIN}`)
},
modules: ['node_modules'],
// Required for some module configs which use these fields
// See https://github.com/flatiron/director/issues/349
mainFields: ['browserify', 'browser', 'module', 'main']
},
plugins: [
new ExtractTextPlugin({
filename: 'style.css',
disable: false,
allChunks: true
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
options: {
context: __dirname
}
})
]
};
if (TEST) {
config.externals = {
cheerio: 'window',
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
};
}
if (PRODUCTION) {
config.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}));
}
module.exports = config;