forked from Regexcellence/Regexcellence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
131 lines (125 loc) · 2.91 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const path = require('path');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const validate = require('webpack-validator');
const parts = require('./libs/parts');
const pkg = require('./package.json');
// occurence order; dedup
const PATHS = {
app: path.join(__dirname, 'client'),
style: [
path.join(__dirname, 'client/styles', 'main.scss')
],
build: path.join(__dirname, 'build'),
fonts: path.join(__dirname, 'client/styles/fonts')
};
const common = {
entry: {
app: PATHS.app + '/app.jsx',
style: PATHS.style,
vendor: PATHS.app + '/vendor.jsx'
},
output: {
path: PATHS.build,
filename: "[name].js"
},
plugins: [
new HtmlWebpackPlugin({
title: 'Regexcellence',
template: PATHS.app + '/index.ejs'
})
],
module: {
loaders: [
{
test: /\.jsx?$/,
//Cache directory improves performance.
loaders: ['babel?cacheDirectory'],
include: PATHS.app,
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.node$/,
loader: 'node-loader'
},
{
test: /\.woff$/,
loader: 'url?limit=50000',
include: PATHS.fonts
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass'],
include: PATHS.style
},
{
test: /\.png$/,
loader: "url-loader?limit=8192",
},
],
},
externals: {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
},
resolve: {
//Empty string needed.
extensions: ['', '.js', '.jsx', '.node']
},
node: {
// For fixing erorr in modules 'fs' and 'net'; console/tls for mongoose error.
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
var config;
const TARGET = process.env.npm_lifecycle_event;
// Detect how npm is run and branch based on that
process.env.BABEL_ENV = TARGET;
switch(TARGET) {
case 'build':
config = merge(common,
{
devtool: 'source-map',
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
// This is used for require.ensure. The setup
// will work without but this is useful to set.
chunkFilename: '[chunkhash].js'
}
},
parts.clean(PATHS.build),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.extractBundle({
name: 'vendor',
entries: ['react', 'redux', 'react-redux']
}),
parts.minify(),
parts.extractCSS(PATHS.style),
parts.purifyCSS([PATHS.app])
);
break;
default:
config = merge(common,
{
devtool: 'source-map'
},
parts.setupCSS(PATHS.style),
parts.devServer({
// Customize host/port here if needed
host: process.env.HOST,
port: process.env.PORT
})
);
}
module.exports = validate(config);