-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
84 lines (78 loc) · 2.3 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
import path from "path";
import CopyPlugin from "copy-webpack-plugin";
import { fileURLToPath } from "url";
import TerserPlugin from "terser-webpack-plugin";
// Because __dirname available for CommonJS but not Module JS
// https://iamwebwiz.medium.com/how-to-fix-dirname-is-not-defined-in-es-module-scope-34d94a86694d
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
/*
import webpack from 'webpack';
const config: webpack.Configuration = {
*/
const config = {
entry: {
background: path.resolve(__dirname, "source/scripts/background.ts"),
content: path.resolve(__dirname, "source/scripts/content.ts"),
data: path.resolve(__dirname, "source/scripts/data.ts"),
types: path.resolve(__dirname, "source/scripts/types.ts"),
utilities: path.resolve(__dirname, "source/scripts/utilities.ts"),
},
output: {
path: path.resolve(__dirname, "build"),
filename: "scripts/[name].js",
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "source/*.json", to: "[name].json" },
{ from: "source/icons/*", to: "icons/[name][ext]" },
{ from: "source/styles/*", to: "styles/[name][ext]" },
],
}),
],
};
export default (env, argv) => {
if (argv.mode === "development") {
config.mode = "development";
config.devtool = "eval";
}
if (argv.mode === "production") {
config.mode = "production";
config.optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
// sourceMap minify option true if using source-maps in production
// requires setting corresponding sourceMap object compress option
//sourceMap: true,
terserOptions: {
// compress options:
// https://github.com/terser/terser?tab=readme-ov-file#compress-options
compress: {
// drop console.debug, console.info, console.log
// keep console.error, console.trace, console.warn
drop_console: ["debug", "info", "log"],
},
// sourceMap options:
// https://github.com/terser/terser?tab=readme-ov-file#source-map-options
//sourceMap: {},
},
}),
],
};
}
return config;
};