This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
forked from diegohaz/arc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (107 loc) · 2.69 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
// https://github.com/diegohaz/arc/wiki/Webpack
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const WebpackMd5Hash = require('webpack-md5-hash')
const HappyPack = require('happypack')
const mergeWith = require('lodash/mergeWith')
const isArray = require('lodash/isArray')
const host = process.env.HOST || 'localhost'
const port = process.env.PORT || 3000
const sourceDir = process.env.SOURCE || 'src'
const publicPath = `/${process.env.PUBLIC_PATH || ''}/`.replace('//', '/')
const sourcePath = path.join(process.cwd(), sourceDir)
const outputPath = path.join(process.cwd(), 'dist')
function customizer(objValue, srcValue) {
if (isArray(objValue)) {
return objValue.concat(srcValue)
}
return undefined
}
const wpConfig = {
base: {
module: {
rules: [
{ test: /\.jsx?$/, exclude: /node_modules/, use: 'happypack/loader' },
{ test: /\.(png|jpe?g|svg|woff2?|ttf|eot)$/, loader: 'url-loader?limit=8000' },
],
},
plugins: [
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(process.cwd(), 'public/index.html'),
}),
new HappyPack({
loaders: ['babel-loader'],
}),
new webpack.DefinePlugin({
NODE_ENV: process.env.NODE_ENV,
PUBLIC_PATH: publicPath.replace(/\/$/, ''),
}),
],
resolve: {
extensions: ['.js', '.jsx', '.json'],
modules: [].concat(sourceDir, ['node_modules']),
},
entry: {
app: [sourcePath],
},
output: {
filename: '[name].js',
path: outputPath,
publicPath,
},
},
development: {
mode: 'development',
plugins: [
new webpack.HotModuleReplacementPlugin({
fullBuildTimeout: 200,
}),
],
entry: {
app: ['webpack/hot/only-dev-server'],
},
devtool: 'cheap-module-source-map',
devServer: {
hot: true,
historyApiFallback: { index: publicPath },
inline: true,
contentBase: 'public',
headers: { 'Access-Control-Allow-Origin': '*' },
host,
port,
stats: 'errors-only',
},
optimization: {
namedModules: true,
},
},
production: {
mode: 'production',
plugins: [
new WebpackMd5Hash(),
],
output: {
filename: '[name].[chunkhash].js',
},
optimization: {
minimizer: [
new UglifyJsPlugin(),
],
splitChunks: {
name: 'vendor',
minChunks: 2,
},
},
},
}
const config = mergeWith(
{},
wpConfig.base,
wpConfig[process.env.NODE_ENV],
customizer,
)
module.exports = config