-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
144 lines (134 loc) · 3.3 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
132
133
134
135
136
137
138
139
140
141
142
143
144
const path = require('path')
const merge = require('webpack-merge')
const webpack = require('webpack')
const pkg = require('./package.json')
const Clean = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const TARGET = process.env.npm_lifecycle_event
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build')
}
process.env.BABEL_ENV = TARGET
const common = {
//Entry accepts a path or an object of entries
// the build chapter contains an example of the latter
entry: PATHS.app,
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: PATHS.build,
filename: '[name].js'
},
module: {
loaders: [
//Set up jsx. This accepts js too thanks to RegExp
{
test: /\.jsx?$/,
//Enable caching for improved performance during development
//it uses default OS directory by default. If you need something
//more custom, pass a path to it. I.e., babel?cacheDirectory=<path>
loaders: ['babel?cacheDirectory'],
include: PATHS.app
},
{
test: /\.(png|jpg|ico)$/,
loader: 'url?limit=25000'
},
{
test: /\.json$/,
loaders: ['json-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'node_modules/html-webpack-template/index.html',
title: 'kDaemon',
appMountId: 'app',
inject: false,
favicon: './app/images/favicon.ico'
})
]
}
//Default configuration
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
//Enable history API fallback so HTML5 History API based
//routing works. This is a good default that will come
//in handy in more complicated setups
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
//display only errors to reduce the amount of output.
stats: 'errors-only',
//Parse host and port from env so this is easy to customize
host: process.env.HOST,
port: process.env.PORT
},
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.app
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
})
}
if (TARGET === 'build' || TARGET === 'stats') {
module.exports = merge(common, {
entry: {
app: PATHS.app,
vendor: Object.keys(pkg.dependencies).filter(function(v) {
//Exclude alt-utils as it won't work with this setup
//due to the way the package has been designed
// (no package.json main)
return v!== 'alt-utils'
})
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css'),
include: PATHS.app
}
]
},
plugins: [
//Extract vendor and manifest files
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
//Setting DefinePlugin affect React library size!
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings:false
}
}),
new Clean([PATHS.build], {
verbose: true
}),
//Output extracted CSS to a file
new ExtractTextPlugin('styles.[chunkhash].css')
]
})
}