-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
91 lines (85 loc) · 1.88 KB
/
webpack.config.babel.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
import {
DefinePlugin,
optimize,
HotModuleReplacementPlugin,
Configuration
} from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import CleanWebpackPlugin from "clean-webpack-plugin";
import CopyWebpackPlugin from "copy-webpack-plugin";
import GitRevisionPlugin from "git-revision-webpack-plugin";
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
import { resolve } from "path";
const gitVersion = JSON.stringify(
new GitRevisionPlugin({ versionCommand: "log -1 --oneline" }).version()
);
/** @type Configuration */
const config = {
// Entry points to the project
entry: {
main: "./src/app.js"
},
devServer: {
contentBase: "./static/",
hot: true,
inline: true,
open: true
},
devtool: "inline-source-map",
output: {
path: resolve(__dirname, "public"),
filename: "[name].js",
globalObject: "this"
},
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
exclude: /node_modules/,
use: ["babel-loader"]
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
},
plugins: [
new CleanWebpackPlugin(["public"]),
new DefinePlugin({
VERSION: gitVersion
}),
new HtmlWebpackPlugin({
template: "./static/index.html",
VERSION: gitVersion
}),
new CopyWebpackPlugin([{ from: "./static" }])
]
};
if (process.env.NODE_ENV === "production") {
config.optimization = {
splitChunks: {
chunks: "all"
},
minimizer: [
new UglifyJsPlugin({
sourceMap: true
})
]
};
config.plugins.push(
new DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
);
} else {
config.plugins.push(new HotModuleReplacementPlugin());
}
export default config;