-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
67 lines (62 loc) · 1.54 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
'use strict'
const webpack = require('webpack')
, babel = require('./babel.config')
, {isHot, isProd} = require('./env.config')
const config = env => ({
entry: entries(env, './main.js'),
output: {
filename: 'bundle.js',
path: `${__dirname}/public`,
},
devtool: 'source-map',
resolve: {
extensions: [ '.jsx', '.js', '.json' ],
alias: {
// This lets us use '~' to mean 'the root of the app' in import
// statements.
'~': __dirname
}
},
devServer: devServer(env),
module: {
rules: [{
test: /jsx?$/,
exclude: /node_modules/,
use: babel(env),
},
{
test: /\.(jpeg|jpg|png|)$/,
use: 'url-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(txt|md|markdown)$/,
use: 'raw-loader',
}]
},
plugins: plugins(env),
})
const entries = (env, entry) =>
isHot(env)
? ['react-hot-loader/patch', 'babel-polyfill', entry]
: ['babel-polyfill', entry]
const plugins = env => isHot(env) ? [
new webpack.HotModuleReplacementPlugin, // Enable HMR globally
new webpack.NamedModulesPlugin, // Better module names in the browser
// console on HMR updates
new webpack.NoEmitOnErrorsPlugin, // Don't emit on errors.
] : []
function devServer(env) {
if (isProd(env)) return
const {FIREBASE_SERVE_URL} = env
return {
hot: true,
proxy: FIREBASE_SERVE_URL && {
"/": FIREBASE_SERVE_URL
}
}
}
module.exports = config(process.env)