-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
95 lines (87 loc) · 2.08 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
const {resolve} = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const {version} = require('./package.json')
module.exports = (env) => {
const isProd = env === 'production'
const plugins = [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(version)
}),
new webpack.ProvidePlugin({
i18n: 'i18next',
Promise: 'bluebird',
React: 'react'
}),
// Remove unnecessary moment.js locales
// http://stackoverflow.com/a/25426019
new webpack.ContextReplacementPlugin(/moment\/locale/, /ru/),
// Create vendor.js bundle from node_modules imports
// https://github.com/webpack/webpack/issues/2372#issuecomment-213149173
new webpack.optimize.CommonsChunkPlugin({
minChunks: ({resource}) => /node_modules/.test(resource),
name: 'vendor'
}),
new HtmlWebpackPlugin({
template: resolve('src/client/index.html')
})
]
if (isProd) {
plugins.push(new ExtractTextPlugin('[name].bundle.[contenthash:4].css'))
} else {
plugins.push(new webpack.NamedModulesPlugin())
}
return {
entry: [
'regenerator-runtime/runtime',
resolve('src/client')
],
output: {
filename: isProd
? '[name].bundle.[chunkhash:4].js'
: '[name].bundle.js',
path: resolve('public'),
publicPath: '/'
},
stats: {modules: false},
devtool: 'cheap-module-source-map',
devServer: {
stats: {modules: false},
historyApiFallback: true,
contentBase: resolve('public'),
proxy: {
'/ycm': {
target: 'http://youcomedy.me',
changeOrigin: true,
pathRewrite: {'^/ycm' : ''}
}
}
},
resolve: {
alias: {
react: 'inferno-compat',
'react-dom': 'inferno-compat'
},
modules: [
resolve('src/client'),
resolve('node_modules')
]
},
plugins,
module: {
rules: [{
test: /\.js$/,
use: 'babel-loader'
}, {
test: /\.css$/,
use: isProd
? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
: ['style-loader', 'css-loader']
}]
}
}
}