-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
95 lines (93 loc) · 2.19 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 webpack = require("webpack");
const prod = 0 <= process.argv.indexOf("-p");
const path = require("path");
module.exports = {
entry: {
main: hotInject("./app/index.js")
},
output: {
path: path.join(__dirname, "docs"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.(js|jsx|es6)$/,
use: ["babel-loader"],
exclude: /node_modules/
},
{
test: /\.css$/,
use: ["style-loader", "css-loader?importLoaders=1", "postcss-loader"]
},
{
test: /\.png$/,
use: [
{
loader: "file-loader",
query: {
hash: "sha512",
name: "[hash].[ext]"
}
},
{
loader: "image-webpack-loader",
query: {
bypassOnDebug: true
}
}
]
}
]
},
resolve: {
modules: [path.resolve("./node_modules"), path.resolve("./app")]
},
context: __dirname,
devtool: prod ? "source-map" : "eval-source-map",
devServer: {
hot: true,
contentBase: path.join(__dirname, "dev"),
publicPath: prod ? "/pixelFactory/" : "/",
historyApiFallback: true,
port: 8080,
headers: {
"Access-Control-Allow-Origin": "*"
}
},
plugins: prod
? [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
}),
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 10000
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true
}),
new webpack.optimize.AggressiveMergingPlugin()
]
: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
};
function hotInject(path) {
return prod
? [path]
: [
"react-hot-loader/patch",
"webpack-dev-server/client?http://localhost:8080",
"webpack/hot/only-dev-server",
path.replace(/\.js/, ".dev.js")
];
}