-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
91 lines (83 loc) · 2.37 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
var path = require('path'),
_ = require('lodash'),
webpack = require('webpack'),
ExtractTextPlugin = require('extract-text-webpack-plugin')
const vendor = [
'lodash',
'react',
'react-dom',
'react-router',
'socket.io-client',
'rxjs'
]
function createConfig(isDebug) {
const devtool = isDebug ? 'eval-source-map' : false
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js'
}),
new webpack.DefinePlugin({
process_env: {
NODE_ENV: `"${process.env.NODE_ENV || "development"}"}`
},
IS_PRODUCTION: !isDebug,
IS_DEVELOPMENT: isDebug,
})
]
const loaders = {
js: { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
eslint: { test: /\.jsx?$/, loader: 'eslint-loader', exclude: /node_modules/ },
css: { test: /\.css?$/, use: ['style-loader', 'css-loader?sourceMap'] },
sass: { test: /\.scss?$/, use: ['style-loader', 'css-loader?sourceMap', 'sass-loader?sourceMap'] },
files: { test: /\.(png|jpg|jpeg|gif|woff|ttf|eot|svg|woff2)/, loader: 'url-loader?limit=5000'}
}
const clientEntry = ['babel-polyfill', './src/client/client.js']
let publicPath = '/build/'
if (isDebug) {
plugins.push(new webpack.HotModuleReplacementPlugin())
clientEntry.unshift(
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server'
)
publicPath = 'http://localhost:8080/build/'
} else {
plugins.push(
new ExtractTextPlugin('[name].css'),
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false }})
)
loaders.css.use = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
loaders.sass.use = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
return {
name: 'client',
devtool,
entry: {
app: clientEntry,
vendor
},
output: {
path: path.join(__dirname, 'public', 'build'),
filename: '[name].js',
publicPath
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
shared: path.join(__dirname, 'src', 'server', 'shared')
}
},
module: {
rules: _.values(loaders)
},
plugins
}
}
module.exports = createConfig(process.env.NODE_ENV !== 'production')