-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (72 loc) · 2.22 KB
/
webpack.config.js
File metadata and controls
79 lines (72 loc) · 2.22 KB
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
var chalk = require('chalk');
var webpack = require('webpack');
var environments = {
production: {
vendor: ['react', 'react-router'],
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js',
minChunks: Infinity
})
]
},
development: {
vendor: ['webpack-dev-server/client?http://localhost:3000',
'webpack/hot/dev-server',
'react',
'react-router'],
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js',
minChunks: Infinity
}),
new webpack.HotModuleReplacementPlugin()
],
}
};
module.exports = {
context: __dirname + '/app',
entry: {
// output 2 bundles of javascript, one for vendor, one for application
vendor: env('vendor'),
app: './client.jsx'
},
output: {
filename: 'client.js',
path: __dirname + '/dist',
publicPath: '/js'
},
devtool: 'eval',
plugins: env('plugins'),
resolve: {
// Look directly in app dir for modules
root: __dirname + '/app',
// Allow to omit extensions when requiring these files
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loaders: ['babel?sourceMap&experimental'] },
// Pass *.jsx files through jsx-loader transform
{ test: /\.jsx$/, loaders: ['react-hot', 'babel?sourceMap&experimental', 'jsx'] },
{ test: /\.css$/, loaders: ['style', 'css'] }
]
}
}
function env(key) {
var result = undefined;
try {
var env = process.env.NODE_ENV || 'development';
result = environments[env][key];
if (result === undefined) {
console.warn(chalk.yellow('Undefined environment key', key, ' in ', env));
}
return result;
} catch(e) {
console.error(chalk.red('Exception occurred retrieving environment config key', key, ' in ', env));
console.error(e.stack);
process.exit(1);
}
}