-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
119 lines (110 loc) · 3.12 KB
/
webpack.common.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const ZipPlugin = require("zip-webpack-plugin");
module.exports = (env) => {
const distFolder = () => {
// Return name of the dist folders depending on what browser the plugin is being built for
return `dist-${env.label}-${env.browser}-rewrite`;
};
const originManifest = () => {
// Return path to manifest.
// Different browsers might use different manifest formats.
// Return path to chromium manifest per default.
let path = "src/webextension";
if (env.browser === "firefox") {
return `${path}/manifest_firefox.json`;
}
return `${path}/manifest_chrome.json`;
};
const originBackgroundScript = () => {
let path = "src/webextension/background";
if (env.browser === "firefox") {
return `${path}/background_firefox.ts`;
}
return `${path}/background_chrome.ts`;
};
return {
entry: {
options: path.resolve(__dirname, "src/index.tsx"), // Top react component for option's page.
sidepanel: path.resolve(__dirname, "src/sidepanel.tsx"), // Top react component for sidepanel
background: path.resolve(__dirname, originBackgroundScript()), // Script running in the browser's internal environment
contentScript: path.resolve(
__dirname,
"src/webextension/contentScript/contentScript.ts"
) // Script running in the plugin's UI (option's page, sidepanels, controller)
},
module: {
rules: [
{ use: "ts-loader", test: /\.tsx?$/, exclude: /node_modules/ },
{
test: /\.scss$|css$/,
use: [
"style-loader",
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
ident: "postcss",
plugins: [tailwindcss, autoprefixer]
}
}
}
]
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, originManifest()),
to: path.resolve(`${distFolder()}/manifest.json`)
},
{
from: path.resolve(__dirname, "LICENSE.md"),
to: path.resolve(`${distFolder()}/LICENSE.md`)
},
{
from: path.resolve(__dirname, "README.md"),
to: path.resolve(`${distFolder()}/README.md`)
},
{
from: path.resolve(__dirname, originBackgroundScript()),
to: path.resolve(`${distFolder()}/background.js`)
},
{
from: path.resolve(__dirname, "brand"),
to: path.resolve(__dirname, `${distFolder()}/brand`)
}
]
}),
new HtmlPlugin({
title: "Sidepanel",
filename: "sidepanel.html",
chunks: ["sidepanel"]
}),
new HtmlPlugin({
title: "Tab Manager",
filename: "options.html",
chunks: ["options"]
}),
new ZipPlugin({
path: "../",
filename: `${env.browser}-${env.label}-rewrite-package.zip`
})
],
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js", ".css", ".scss"]
},
output: {
filename: "[name].js", // in /dist
path: path.join(__dirname, distFolder()),
clean: true
}
};
};