This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
184 lines (171 loc) · 4.96 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
const ClosurePlugin = require("closure-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const Visualizer = require("webpack-visualizer-plugin");
const DotenvPlugin = require("webpack-dotenv-plugin");
const pjson = require("./package.json");
const DIST_FOLDER = process.env.DIST_FOLDER || "dist";
const REPORT_FOLDER = process.env.REPORT_FOLDER || "docs/reports";
const DEV_STATISTIC_HTML = process.env.DEV_STATISTIC_HTML || "statistics-dev.html";
const STATISTIC_HTML = process.env.STATISTIC_HTML || "statistics.html";
let NODE_ENV = process.env.NODE_ENV || "development";
if (!["development", "testing", "production"].includes(NODE_ENV)) NODE_ENV = "development";
const isDev = NODE_ENV === "development";
const appName = pjson.name;
const appFile = `./${pjson.main}`;
const adminName = pjson.admin.name;
const adminFile = `./${pjson.admin.main}`;
const minimizer = [
new ClosurePlugin(
{
mode: "STANDARD",
childCompilations: true,
},
{
formatting: "PRETTY_PRINT",
debug: isDev,
renaming: !isDev,
},
),
];
if (!isDev)
minimizer.push(
new UglifyJsPlugin({
extractComments: {
condition: true,
banner() {
return `----------------------------------------
01001100 01001001 01000011 01000101 01001110 01010011
01000101 01100010 01111001 01001011 01000011 01000000
00110010 00110000 00110001 00111001 00101110 01010100
01101000 01101001 01110011 01100010 01100001 01101110
01101110 01100101 01110010 01101001 01110011 01100001
01110000 01110010 01101111 01101111 01100110 01100101
01110110 01101001 01100100 01100101 01101110 01100011
01100101 00101110 01111001 01101111 01110101 01101110
01101111 01110100 01100001 01101100 01101100 01101111
01110111 01110100 01101111 01101101 01101111 01100100
01101001 01100110 01111001 00101100 01100011 01101111
01110000 01111001 01101111 01110010 01110011 01100101
01101100 01101100 01110100 01101000 01100101 01100011
01101111 01101101 01101101 01100001 01101110 01100100
----------------------------------------`;
},
},
}),
);
const entry = {};
entry[appName] = appFile;
entry[adminName] = adminFile;
module.exports = {
mode: NODE_ENV,
entry,
module: {
rules: [
{
test: /\.ts$/,
enforce: "pre",
use: [
{
loader: "eslint-loader",
options: {
typeCheck: false,
fix: false,
},
},
],
},
{
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
allowTsInNodeModules: true,
},
},
],
},
{
test: /\.(sass|scss)$/,
use: ["to-string-loader", "css-loader", "sass-loader"],
},
{
test: /\.(html|mustache)$/,
use: [
{
loader: "html-loader",
options: {
minimize: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: false,
minifyJS: true,
},
},
],
},
],
},
optimization: {
nodeEnv: NODE_ENV,
mangleWasmImports: true,
moduleIds: isDev ? "named" : "hashed",
minimize: !isDev,
minimizer,
splitChunks: {
minSize: 0,
},
},
plugins: [
new DotenvPlugin({
sample: "./.env.default",
path: "./.env",
}),
new webpack.DefinePlugin({
__NODE_ENV__: JSON.stringify(NODE_ENV),
__NAME__: JSON.stringify(pjson.name),
__DESCRIPTION__: JSON.stringify(pjson.description),
__AUTHOR__: JSON.stringify(pjson.author),
__VERSION__: JSON.stringify(pjson.version),
__COMPILE_DATE__: JSON.stringify(+new Date()),
__FIREBASE_API_KEY__: JSON.stringify(process.env.FB_API_KEY),
__FIREBASE_AUTH_DOMAIN__: JSON.stringify(process.env.FB_AUTH_DOMAIN),
__FIREBASE_DATABASE_URL__: JSON.stringify("https://nd-cli.firebaseio.com"),
__FIREBASE_PROJECT_ID__: JSON.stringify("nd-cli"),
__FIREBASE_STORAGE_BUCKET__: JSON.stringify(""),
__FIREBASE_MESSAGING_SENDER_ID__: JSON.stringify(process.env.FB_SENDER_ID),
__FIREBASE_APP_ID__: JSON.stringify(process.env.FB_APP_ID),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new Visualizer({
filename: `../${REPORT_FOLDER}/${isDev ? DEV_STATISTIC_HTML : STATISTIC_HTML}`,
}),
],
resolve: {
extensions: [".ts", ".js"],
},
output: {
filename: isDev ? "[name].js" : "[name].min.js",
path: path.resolve(__dirname, DIST_FOLDER),
},
target: "node",
externals: [
nodeExternals({
whitelist: [
/@nd\/*/,
"jsonwebtoken",
"ms",
"chalk",
"debug",
"bcryptjs",
"escape-string-regexp",
"iconv-lite",
"async",
],
}),
],
};