-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathwebpack.js
More file actions
executable file
·244 lines (227 loc) · 7.8 KB
/
Copy pathwebpack.js
File metadata and controls
executable file
·244 lines (227 loc) · 7.8 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
237
238
239
240
241
242
243
244
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const baseManifest = require("./chrome/manifest.json");
const { buildManifest } = require("./chrome/buildManifest");
const WebpackExtensionManifestPlugin = require("webpack-extension-manifest-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = (env = {}, argv) => {
const isProduction = argv.mode === "production";
const isDevelopment = argv.mode === "development";
const target = env.target === "firefox" ? "firefox" : "chrome";
return {
mode: argv.mode,
// Development: fast rebuilds with inline source maps
// Production: external source maps (can be disabled for release)
devtool: isDevelopment
? 'cheap-module-source-map'
: (env.sourcemap !== 'false' ? 'source-map' : false),
entry: {
app: path.join(__dirname, "./static/index.js"),
fullpage: path.join(__dirname, "./static/fullpage.js"),
},
output: {
path: path.resolve(__dirname, target === "firefox" ? "./build-firefox" : "./build"),
// Content-hash entry/chunk filenames in production so Chrome can't serve
// a stale cached bundle across extension reloads (the JS carries the
// injected CSS, so unhashed names caused reloads to keep old styles).
// Dev keeps stable names (watch rewrites them; HTML uses ?hash busting).
filename: isProduction ? "[name].[contenthash].js" : "[name].js",
chunkFilename: isProduction ? "[name].[contenthash].js" : "[name].js",
clean: true, // Clean build folder before each build
},
resolve: {
extensions: ["*", ".js"],
},
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 2020,
},
compress: {
ecma: 2020,
comparisons: false,
inline: 2,
drop_console: isProduction && env.drop_console === 'true',
drop_debugger: isProduction,
pure_funcs: isProduction ? ['console.log'] : [],
},
mangle: {
safari10: true,
},
output: {
ecma: 2020,
comments: false,
ascii_only: true,
},
},
extractComments: false, // Don't create separate LICENSE.txt files
}),
],
// Enable module concatenation (scope hoisting) for smaller bundles
concatenateModules: isProduction,
// Use deterministic IDs for better caching and consistent builds
moduleIds: 'deterministic',
chunkIds: 'deterministic',
// Split vendor code into separate chunks for better caching
splitChunks: isProduction ? {
chunks: 'all',
maxInitialRequests: 25,
minSize: 20000,
cacheGroups: {
// Group React and related packages
react: {
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
name: 'vendor-react',
chunks: 'all',
priority: 40,
},
// Group UI libraries
ui: {
test: /[\\/]node_modules[\\/](react-icons|react-modal|react-select|react-tooltip|react-tiny-popover|react-hot-toast|react-time-ago)[\\/]/,
name: 'vendor-ui',
chunks: 'all',
priority: 30,
},
// Group drag-and-drop libraries
dnd: {
test: /[\\/]node_modules[\\/]@dnd-kit[\\/]/,
name: 'vendor-dnd',
chunks: 'all',
priority: 30,
},
// Remaining vendor modules
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
},
} : undefined,
// Keep runtime chunk inline in app.js for Chrome extensions
runtimeChunk: false,
},
// Disable performance warnings - not relevant for Chrome extensions (local loading)
performance: {
hints: false,
},
// All target browsers have globalThis; without this webpack injects a
// `new Function("return this")` shim that AMO's validator flags as eval.
node: { global: false },
plugins: [
new webpack.DefinePlugin({ global: "globalThis" }),
new HtmlWebpackPlugin({
title: "Tabox - Tab Manager, Save & Share Tab Groups",
meta: {
charset: "utf-8",
viewport: "width=device-width, initial-scale=1, shrink-to-fit=no",
"theme-color": "#000000"
},
filename: "index.html",
template: "./static/index.html",
chunks: ['app'],
hash: !isProduction, // Only add hash in development for cache busting
minify: isProduction ? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
} : false,
}),
new HtmlWebpackPlugin({
title: "Tabox - Full Page View",
meta: {
charset: "utf-8",
viewport: "width=device-width, initial-scale=1, shrink-to-fit=no",
"theme-color": "#000000"
},
filename: "fullpage.html",
template: "./static/fullpage.html",
chunks: ['fullpage'],
hash: !isProduction,
minify: isProduction ? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
} : false,
}),
new CopyPlugin({
patterns: [
{ from: "chrome/icons", to: "icons", globOptions: { ignore: ["**/.DS_Store"] } },
{ from: "static/images", to: "images", globOptions: { ignore: ["**/.DS_Store"] } },
{ from: "static/globals.js", to: "[name][ext]" },
{ from: "static/deferedLoading.*", to: "[name][ext]" },
{ from: "chrome/*.js", to: "[name][ext]", globOptions: { ignore: ["**/buildManifest.js"] } },
{
from: 'node_modules/webextension-polyfill/dist/browser-polyfill.min.*',
to: "[name][ext]"
}
]
}),
new WebpackExtensionManifestPlugin({
config: {
base: buildManifest(baseManifest, target)
}
})
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true, // Cache babel compilations for faster rebuilds
cacheCompression: false, // Faster cache without compression
}
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(png|jpg|gif)$/i,
type: 'asset/resource'
}
]
},
// Cache for faster subsequent builds
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename],
},
name: `${isProduction ? 'production' : 'development'}-${target}`,
},
// Stats configuration for cleaner output
stats: isProduction ? {
assets: true,
chunks: false,
modules: false,
entrypoints: true,
warnings: true,
errors: true,
errorDetails: true,
} : 'normal',
};
};