-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
79 lines (75 loc) · 2.27 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
const path = require("path");
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const MergeJsonWebpackPlugin = require("merge-jsons-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
// Build process inspired by:
// (1) Roskomsvoboda, censortracker, https://github.com/roskomsvoboda/censortracker/
// (2) Gourav Goyal, Notion-Boost-browser-extension, https://github.com/GorvGoyl/Notion-Boost-browser-extension
const BROWSER = process.env.BROWSER;
const ENV = process.env.NODE_ENV;
const IS_CHROME = BROWSER === "chrome";
let copyPatterns = [
{
from: "./src/assets/",
to: path.resolve(__dirname, `dist/${BROWSER}/${ENV}/assets/`),
},
];
let addBrowserPolyfill = false;
if (IS_CHROME) {
copyPatterns.push({
from: "./node_modules/webextension-polyfill/dist/browser-polyfill.min.js",
to: path.resolve(
__dirname,
`dist/${BROWSER}/${ENV}/js/browser-polyfill.min.js`
),
});
addBrowserPolyfill = true;
}
module.exports = {
mode: ENV,
devtool: "source-map",
entry: {
"js/background": "./src/js/background.js",
"js/popup": "./src/js/popup.js",
},
output: {
path: path.resolve(__dirname, `dist/${BROWSER}/${ENV}/`),
filename: "[name].js",
},
resolve: {
fallback: {
os: false,
},
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
path.resolve(__dirname, `dist/${BROWSER}/${ENV}/`),
],
}),
new MergeJsonWebpackPlugin({
files: [
"./src/manifest.common.json",
`./src/manifest.${BROWSER}.json`,
],
output: {
fileName: "manifest.json",
},
}),
new CopyPlugin({
patterns: copyPatterns,
}),
new HtmlWebpackPlugin({
title: "Censorship Detector",
inject: false,
filename: "popup.html",
template: "./src/popup.ejs",
addBrowserPolyfill,
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
};