-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
236 lines (230 loc) · 6.18 KB
/
Copy pathwebpack.config.ts
File metadata and controls
236 lines (230 loc) · 6.18 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import path from "path";
import { Configuration, DefinePlugin } from "webpack";
import packageJson from "./package.json";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebPackPlugin from "html-webpack-plugin";
// @ts-ignore
import CopyWebpackPlugin from "copy-webpack-plugin";
import RemoveFilesWebpackPlugin from "remove-files-webpack-plugin";
const config: Configuration[] = [
// ----------------------------------------------------------------
// GOOGLE CHROME
// ----------------------------------------------------------------
manifest({
entry: `./src/manifest.json`,
outputDirectory: `dist/chrome_extension`,
description: `Highlight occurrences of selected text, with or without a keypress.`,
browserSpecificSettings: null,
}),
content_script({
entry: `./src/content_script/highlighter.ts`,
outputDirectory: `dist/chrome_extension/content_script`,
}),
popup({
doesSupportPaypal: true,
entry: `./src/popup/main.tsx`,
outputDirectory: `dist/chrome_extension/popup`,
}),
// ----------------------------------------------------------------
// MOZILLA FIREFOX
// ----------------------------------------------------------------
manifest({
entry: `./src/manifest.json`,
outputDirectory: `dist/firefox_extension`,
description: `Highlight occurrences of selected text, with or without a keypress.`,
browserSpecificSettings: {
gecko: {
id: `{ee192302-b8b3-450e-a7f8-a3dabdccf2a8}`,
},
},
}),
content_script({
entry: `./src/content_script/highlighter.ts`,
outputDirectory: `dist/firefox_extension/content_script`,
}),
popup({
doesSupportPaypal: true,
entry: `./src/popup/main.tsx`,
outputDirectory: `dist/firefox_extension/popup`,
}),
// ----------------------------------------------------------------
// APPLE SAFARI
// (see build_safari.sh)
// ----------------------------------------------------------------
manifest({
entry: `./src/manifest.json`,
outputDirectory: `build/safari_extension`,
description: `Highlight occurrences of selected text.`,
browserSpecificSettings: null,
}),
content_script({
entry: `./src/content_script/highlighter.ts`,
outputDirectory: `build/safari_extension/content_script`,
}),
popup({
doesSupportPaypal: false,
entry: `./src/popup/main.tsx`,
outputDirectory: `build/safari_extension/popup`,
}),
];
export default config;
type ManifestConfig = {
entry: string;
outputDirectory: string;
description: string;
browserSpecificSettings: {
gecko: {
id: string;
};
} | null;
};
function manifest({
entry,
outputDirectory,
description,
browserSpecificSettings,
}: ManifestConfig): Configuration {
return {
entry: entry,
output: {
path: path.resolve(__dirname, outputDirectory),
filename: `DELETED.js`,
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: `LICENSE.md`,
},
{
from: entry,
transform: function (manifestBuffer: Buffer, path: string) {
let manifestString = manifestBuffer
.toString()
.replace(/\$\{DESCRIPTION\}/, description)
.replace(/\$\{PACKAGE_VERSION\}/g, packageJson.version);
if (browserSpecificSettings) {
const manifestJson = JSON.parse(manifestString);
manifestJson.browser_specific_settings =
browserSpecificSettings;
manifestString = JSON.stringify(manifestJson, null, 2);
}
return Buffer.from(manifestString);
},
},
{
from: `src/images/icon.png`,
to: `images`,
},
],
}),
new RemoveFilesWebpackPlugin({
after: {
log: false,
include: [`${outputDirectory}/DELETED.js`],
},
}),
],
stats: true,
mode: `none`,
};
}
type ContentScriptConfig = {
entry: string;
outputDirectory: string;
};
function content_script({
entry,
outputDirectory,
}: ContentScriptConfig): Configuration {
return {
entry: entry,
output: {
path: path.resolve(__dirname, outputDirectory),
},
module: {
rules: [
{
resolve: {
extensions: [`.js`, `.jsx`, `.ts`, `.tsx`],
},
test: /\.(js|jsx|ts|tsx)$/i,
use: [
{
loader: `babel-loader`,
options: {
presets: [
`@babel/preset-typescript`,
[`@babel/preset-react`, { runtime: `automatic` }],
],
},
},
],
},
],
},
stats: true,
mode: `none`,
};
}
type PopupConfig = {
doesSupportPaypal: boolean;
entry: string;
outputDirectory: string;
};
function popup({
doesSupportPaypal,
entry,
outputDirectory,
}: PopupConfig): Configuration {
return {
entry: entry,
output: {
path: path.resolve(__dirname, outputDirectory),
},
plugins: [
new HtmlWebPackPlugin({
title: `Selection Highlighter Options`,
}),
new DefinePlugin({
"process.env.DOES_SUPPORT_PAYPAL": JSON.stringify(doesSupportPaypal),
}),
],
module: {
rules: [
{
resolve: {
extensions: [`.js`, `.jsx`, `.ts`, `.tsx`],
},
test: /\.(js|jsx|ts|tsx)$/i,
use: [
{
loader: `babel-loader`,
options: {
presets: [
`@babel/preset-typescript`,
[`@babel/preset-react`, { runtime: `automatic` }],
],
},
},
],
},
{
test: /\.(jpg|jpeg|png|gif|eot|otf|svg|ttf|woff|woff2)$/i,
use: [
{
loader: `file-loader`,
options: {
esModule: false,
name: `[name].[ext]`,
},
},
],
},
],
},
stats: true,
mode: `none`,
};
}