-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
214 lines (197 loc) · 5.56 KB
/
webpack.config.babel.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import path from 'path';
import webpack from 'webpack';
import merge from 'webpack-merge';
import copy from 'copy-webpack-plugin';
const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v');
const TARGET = process.env.NODE_ENV;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'dist')
};
process.env.BABEL_ENV = TARGET;
const common = {
context: __dirname,
// The entry point for the bundle
entry: [
'babel-polyfill',
/* Material Design Lite (https://getmdl.io) */
'!!style!css!dialog-polyfill/dialog-polyfill.css',
'!!style!css!react-mdl/extra/material.min.css',
'react-mdl/extra/material.min.js',
/* The main entry point of your JavaScript application */
'./app/main.js',
],
// Options affecting the output of the compilation
output: {
path: path.resolve(PATHS.build, './assets'),
publicPath: '/assets/',
sourcePrefix: ' ',
},
resolve: {
extensions: ['', '.js', '.jsx']
},
// What information should be printed to the console
stats: {
colors: true,
hash: isVerbose,
version: isVerbose,
timings: true,
chunks: isVerbose,
chunkModules: isVerbose,
cached: isVerbose,
cachedAssets: isVerbose,
},
// The list of plugins for Webpack compiler
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new copy([
{
from: path.resolve(PATHS.app, './public'),
to: PATHS.build
}
])
],
// Options affecting the normal modules
module: {
loaders: [
{
test: /\.jsx?$/,
include: [
path.resolve(PATHS.app)
],
loader: 'babel-loader',
exclude: [
path.resolve(__dirname, "node_modules"),
]
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader?limit=10000',
},
{
test: /\.(eot|ttf|wav|mp3)$/,
loader: 'file-loader',
},
{
test: /\.json$/,
loader: 'json'
},
]
},
};
const development = {
output: {
filename: '[name].js',
chunkFilename: '[id].js',
},
debug: true,
devtool: 'source-map',
stats: {
reasons: true,
},
devServer: {
contentBase: PATHS.build,
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
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
__DEV__: true,
'process.env.BABEL_ENV': '"production"'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
test: /\.css/,
loaders: [
'style-loader',
`css-loader?${JSON.stringify({
sourceMap: true,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: '[name]_[local]_[hash:base64:3]',
minimize: false,
})}`,
// 'postcss-loader',
],
},
]
}
};
const production = {
output: {
filename: '[name].js',
chunkFilename: '[id].js',
},
debug: false,
devtool: false,
stats: {
reasons: false,
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
__DEV__: false,
'process.env.BABEL_ENV': '"production"'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
},
mangle: {
except: ['$super', '$', 'exports', 'require']
},
output: {
comments: false
}
}),
new webpack.optimize.AggressiveMergingPlugin()
],
module: {
loaders: [
{
test: /\.css/,
loaders: [
'style-loader',
`css-loader?${JSON.stringify({
sourceMap: false,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: '[hash:base64:4]',
// CSS Nano http://cssnano.co/options/
minimize: true,
})}`,
// 'postcss-loader',
],
},
]
}
};
let config;
if (TARGET === 'production') {
config = merge(common, production);
} else {
config = merge(common, development);
}
export default config;