-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
69 lines (64 loc) · 2.04 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
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require("webpack");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const isEnvDevelopment = process.env.NODE_ENV !== "production";
const tsRule = { test: /\.tsx?$/, loader: "ts-loader" };
const extensionConfig = (env, args) => {
return {
context: __dirname,
name: "extension",
mode: isEnvDevelopment ? "development" : "production",
// In development environment, turn on source map.
devtool: isEnvDevelopment ? "inline-source-map" : false,
// In development environment, webpack watch the file changes, and recompile
watch: isEnvDevelopment,
entry: {
popup: ["./src/ui/popup.tsx"],
},
output: {
path: path.resolve(
__dirname,
isEnvDevelopment ? "dist/dev" : "dist/prod"
),
filename: "[name].bundle.js",
},
module: {
rules: [tsRule],
},
plugins: [
// Remove all and write anyway
// TODO: Optimizing build process
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: "./src/chromium_extension/manifest.json",
},
{
from: "node_modules/webextension-polyfill/dist/browser-polyfill.js",
},
{
from: "./src/ui/popup.html",
transformPath(targetPath, absolutePath) {
return targetPath.replace(/src\/ui\//, "");
},
},
{
from: "./src/assets/icons/**/*.png",
transformPath(targetPath, absolutePath) {
return targetPath.replace(/src\//, "");
},
},
],
}),
new WriteFilePlugin(),
new webpack.EnvironmentPlugin(["NODE_ENV"]),
],
};
};
module.exports = extensionConfig;