-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·119 lines (112 loc) · 4.1 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
114
115
116
117
118
119
const webpack = require("webpack");
const {resolve} = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const Dotenv = require('dotenv-webpack');
module.exports = env => {
const plugins = [
new webpack.EnvironmentPlugin({
NODE_ENV: env === "dev" ? "development" : "production",
REACT_APP_API_URL: env === "dev" ? "http://localhost:12345/api/" : JSON.stringify(process.env.REACT_APP_API_URL),
VERSION: require("./package.json").version,
BUILD_TIME: Date.now(),
}),
new HtmlWebpackPlugin({
template: resolve(__dirname, "./src/index.html"),
path: "../",
}),
new Dotenv(),
];
let optimization = {};
if (env !== "dev") {
optimization = {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 0,
maxSize: 20000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/,
)[1];
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
};
}
return {
mode: env === "dev" ? "development" : "production",
devtool:
env === "dev"
? "cheap-module-eval-source-map"
: "hidden-source-map",
context: resolve(__dirname, "./src/client"),
entry: ["./index.js"],
node: {
fs: "empty"
},
module: {
rules: [
{
test: /\.(png|jpg|gif|svg|mp3)$/,
use: [
{
loader: "file-loader",
options: {
name: "[path][name].[ext]",
},
},
],
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: env === "development",
presets: [
"@babel/preset-env",
"@babel/preset-react",
],
plugins: [
[
"@babel/plugin-proposal-decorators",
{
legacy: true,
},
],
"@babel/plugin-proposal-object-rest-spread",
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
],
},
},
],
},
],
},
plugins,
optimization,
performance: {hints: false},
output: {
path: resolve(__dirname, "./bin/client"),
filename: env === "dev" ? "js/bundle.js" : "js/[chunkhash].js",
},
watch: env === "dev",
};
};