-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
76 lines (65 loc) · 1.94 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
var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')
var ExtractTextPlugin = require('extract-text-webpack-plugin');
function isDevelopmentEnvironment(){
return process.env.NODE_ENV === 'development'
}
function buildEntry(){
entry = {
app: [ './javascript/src/index.js'],
statistics: [ './javascript/src/statistics/index.js'],
nn_performance: [ './javascript/src/nn_performance/index.js'],
home: [ './javascript/src/home/index.js'],
recommendation: [ './javascript/src/recommendation/index.js'],
}
if (isDevelopmentEnvironment()) {
Object.keys(entry).forEach(function (key) {
entry[key].unshift('webpack/hot/only-dev-server');
entry[key].unshift('webpack-dev-server/client?http://localhost:3000');
});
}
return entry;
}
function buildOutput(){
return {
path: path.resolve(__dirname, 'public/bundles'),
filename: "[name]-[hash].js",
publicPath: isDevelopmentEnvironment() ?
'http://localhost:3000/assets/bundles/' : '/static/bundles/',
};
}
module.exports = {
context: path.resolve(__dirname, 'app/assets/'),
entry: buildEntry(),
output: buildOutput(),
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new BundleTracker({filename: './webpack-stats.json'}),
new ExtractTextPlugin('[name]-[hash].css'),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}
],
},
resolve: {
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.jsx']
}
};