-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
93 lines (89 loc) · 3.07 KB
/
Copy pathwebpack.config.js
File metadata and controls
93 lines (89 loc) · 3.07 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
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
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const { version } = require("./package.json");
module.exports = (_env, argv) => {
const isDevelopment = argv.mode === "development";
// Entry points for production mode
const entries = {
contextDetect: "./src/index.ts",
// telemetryExample: "./src/scripts/telemetryExample.ts",
};
// Additional entries for development mode
if (isDevelopment) {
// entries.toolkit = "./src/util/toolkit.ts";
}
// Create a separate bundle for each entry point
return Object.keys(entries).map((entry) => ({
mode: isDevelopment ? "development" : "production",
devtool: "source-map",
entry: {
[entry]: entries[entry],
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
library: "[name]", // Expose name to global scope (e.g. jquery => $ or jQuery, lodash => _)
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "this",
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
configFile: isDevelopment ? "tsconfig.dev.json" : "tsconfig.prod.json",
},
},
],
exclude: /node_modules/,
},
// {
// test: /\.css$/i,
// type: "asset/source",
// },
// {
// test: /\.html$/i,
// type: "asset/source",
// },
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new webpack.DefinePlugin({
"process.env.VERSION": JSON.stringify(version),
}),
new webpack.ProvidePlugin({
log: ["/src/logging", "Logger", "log"],
LogLevels: ["/src/logging", "Logger"],
}),
],
optimization: {
// Configure optimization depending on the entry and mode (dev vs prod).
// Don't include source maps in distributed packages.
// https://stackoverflow.com/questions/41040266/remove-console-logs-with-webpack-uglify
minimize: !isDevelopment,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
format: {
comments: false,
},
mangle: false,
},
extractComments: false,
}),
],
},
}));
};