-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (80 loc) · 2.05 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const devServer = require('@webpack-blocks/dev-server2')
const splitVendor = require('webpack-blocks-split-vendor')
const happypack = require('webpack-blocks-happypack')
const {
addPlugins, createConfig, entryPoint, env, setOutput,
sourceMaps, defineConstants, webpack,
} = require('@webpack-blocks/webpack2')
const host = process.env.HOST || '0.0.0.0'
const port = process.env.PORT || 3000
const publicPath = `/${process.env.PUBLIC_PATH || ''}/`.replace('//', '/')
const sourcePath = path.join(process.cwd(), 'src')
const outputPath = path.join(process.cwd(), 'dist')
const babel = () => () => ({
module: {
rules: [
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader' },
],
},
})
const config = createConfig([
entryPoint({
app: sourcePath,
}),
setOutput({
filename: '[name].[hash].js',
path: outputPath,
publicPath,
}),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV,
'process.env.PUBLIC_PATH': publicPath,
}),
addPlugins([
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(process.cwd(), 'public/index.html'),
}),
]),
happypack([
babel(),
]),
() => ({
resolve: {
modules: ['src', 'node_modules'],
},
module: {
rules: [
{ test: /\.(png|jpe?g|svg)$/, loader: 'url-loader?&limit=8000' },
{ test: /\.(woff2?|ttf|eot)$/, loader: 'url-loader?&limit=8000' },
{
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
}
],
},
}),
env('development', [
devServer({
contentBase: 'public',
stats: 'errors-only',
publicPath,
host,
port,
}),
sourceMaps(),
addPlugins([
new webpack.NamedModulesPlugin(),
]),
]),
env('production', [
splitVendor(),
addPlugins([
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
]),
]),
])
module.exports = config