Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
64 lines (61 loc) · 1.65 KB
/
Copy pathwebpack.config.js
File metadata and controls
64 lines (61 loc) · 1.65 KB
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
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const { scriptOutputName, version } = require("./package.json");
if (!scriptOutputName) {
throw new Error('"scriptOutputName" must be set in package.json');
}
/**
* Firebot loads exactly one CommonJS file whose default export is the script
* object. The output must therefore be a single self-contained bundle with the
* public function names (`run`, `getScriptManifest`, `getDefaultParameters`)
* preserved so Firebot can call them.
*/
module.exports = (env, argv) => {
const isProduction = argv.mode === "production";
return {
target: "node",
entry: "./src/main.ts",
output: {
libraryTarget: "commonjs2",
libraryExport: "default",
path: path.resolve(__dirname, "dist"),
filename: `${scriptOutputName}.js`,
clean: true,
},
devtool: isProduction ? false : "source-map",
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new webpack.DefinePlugin({
__SCRIPT_VERSION__: JSON.stringify(version),
}),
],
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
// Do not mangle: Firebot calls the public functions by name.
mangle: false,
keep_fnames: /main/,
format: {
comments: false,
},
},
}),
],
},
};
};