-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwebpack.config.js
55 lines (52 loc) · 1.65 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
const path = require("path");
const webpack = require("webpack");
const fs = require("fs");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const env = {};
const vars = fs.readFileSync("./.env").toString().split("\n");
for (const envVar of vars) {
let val = envVar.replace(/^[^=]*=/g, "");
if (val.indexOf("base64:") === 0) {
val = Buffer.from(val.replace(/base64:/, ""), "base64").toString();
}
env[envVar.replace(/=.*$/g, "")] = val;
}
module.exports = (webpackEnv) => {
webpackEnv = webpackEnv || {};
return {
entry: "./src/background/index.ts",
plugins: [
new webpack.EnvironmentPlugin(env),
new CopyWebpackPlugin([{
from: "node_modules/webextension-polyfill/dist/browser-polyfill.js",
},
{
from: "src/_locales",
to: "_locales",
}]),
],
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: require.resolve("ts-loader"),
options: {
context: __dirname,
configFile: "tsconfig.background.json",
},
},
],
},
resolve: {
extensions: [".ts", ".js", ".json"],
},
output: {
filename: "background.js",
path: path.resolve(__dirname, "build"),
},
target: "web",
devtool: webpackEnv.NODE_ENV === "development" ? "source-map" : undefined,
watch: webpackEnv.NODE_ENV === "development",
};
};