-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
78 lines (72 loc) · 1.67 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
const webpack = require("webpack");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const path = require("path");
// Set up PATHS constants
const PATHS = {
app: path.join(__dirname, "app"),
build: path.join(__dirname, "dist")
};
const config = {
entry: [PATHS.app],
output: {
path: PATHS.build,
filename: "bundle.js",
publicPath: "dist/"
},
module: {
rules: [
{
test: [/\.js$/, /\.jsx$/],
use: ["babel-loader"],
include: PATHS.app
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: "graphql-tag/loader"
}
]
},
resolve: {
modules: [path.resolve("./app"), "node_modules"],
extensions: [".js", ".jsx", ".json"]
},
devServer: {
hot: true,
inline: true,
port: 8080,
overlay: true
}
};
// Plugins
// Create an HTML page on root
const htmlPlugin = new HtmlWebPackPlugin({
template: PATHS.app + "/index.html",
filename: "../index.html",
inject: "body"
});
module.exports = (_env, argv) => {
if (argv.mode === "development") {
config.mode = "development";
config.devtool = "cheap-module-inline-source-map";
config.plugins = [htmlPlugin];
}
if (argv.mode === "production") {
config.mode = "production";
config.devtool = "cheap-module-source-map";
config.plugins = [
htmlPlugin,
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
];
config.optimization = {
minimize: true,
minimizer: [new UglifyJsPlugin()]
};
}
return Object.assign({}, config);
};