-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
81 lines (72 loc) · 1.84 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
'use strict'
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const NODE_ENV = process.env.NODE_ENV
const BUILDING = process.env.npm_lifecycle_event === 'build'
module.exports = (function makeWebpackConfig () {
let entry = []
entry.push('react-hot-loader/patch')
if (!BUILDING) {
entry.push(
'webpack-dev-server/client?http://localhost:7000',
'webpack/hot/only-dev-server'
)
}
entry.push('./main.jsx')
let config = {
entry: entry,
devServer: {
hot: true,
port: 7000,
historyApiFallback: true,
contentBase: './public/'
},
devtool: BUILDING ? 'cheap-module-source-map' : 'eval-source-map',
resolve: {
extensions: ['.js', '.jsx']
},
output: {
path: root('dist'),
filename: BUILDING ? 'js/[name].[hash].js' : 'js/[name].js',
chunkFilename: BUILDING ? '[id].[hash].chunk.js' : '[id].chunk.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV)
}
}),
new HtmlWebpackPlugin({
template: './public/index.html',
chunksSortMode: 'dependency'
})
]
}
if (BUILDING) {
config.plugins.push(
new webpack.NoErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new CopyWebpackPlugin([{
from: root('public')
}])
)
}
return config
})()
// Helpers
function root (args) {
args = Array.prototype.slice.call(arguments, 0)
return path.join.apply(path, [__dirname].concat(args))
}