Files
pezkuwi-extension/packages/extension/webpack.shared.cjs
T
Satoshi Qazi Muhammed bb919831e9 Drop the dead crypto-browserify fallback; resolve braces to @pezkuwi/braces
elliptic (open advisories, no fixed version) came only through
crypto-browserify, the webpack fallback for node's crypto. Nothing in
the extension uses it: the only 'elliptic' in the built files is a word
in zxcvbn's dictionary. Without the fallback the chrome and firefox
builds contain the same modules with the same bodies; only webpack's
module ids and their order change (one browser-field-ignored module is
now resolved from a different request). A future crypto import now
fails the build instead of shipping a polyfill.

braces resolves to @pezkuwi/braces 3.0.4: braces 3.0.3, the latest upstream release, has an open advisory with no fixed version (CVE-2026-93687, stack exhaustion through deeply nested patterns); the fork rejects nesting deeper than maxDepth (500) with a SyntaxError.
2026-10-10 04:09:37 +04:00

161 lines
4.2 KiB
JavaScript

// Copyright 2019-2026 @pezkuwi/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-extension-manifest-plugin');
const { blake2AsHex } = require('@pezkuwi/util-crypto');
const pkgJson = require('./package.json');
const manifest = require('./manifest.json');
const EXT_NAME = manifest.short_name;
const packages = [
'extension',
'extension-base',
'extension-chains',
'extension-dapp',
'extension-inject',
'extension-ui'
];
module.exports = (entry, alias = {}) => ({
context: __dirname,
devtool: false,
entry,
target: ['web', 'es2022'],
module: {
rules: [
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
multiple: [
{
search: /Function\s*\(\s*["']return this["']\s*\)\s*\(\s*\)/g,
replace: 'globalThis'
},
{
search: /Function\s*\(\s*["']return this["']\s*\)/g,
replace: '(function(){return globalThis})'
}
]
}
},
{
exclude: /(node_modules)/,
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
options: {
configFile: 'tsconfig.webpack.json',
transpileOnly: true
}
}
]
},
{
test: [/\.svg$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.woff2?$/],
use: [
{
loader: require.resolve('url-loader'),
options: {
esModule: false,
limit: 10000,
name: 'static/[name].[ext]'
}
}
]
}
]
},
output: {
chunkFilename: '[name].js',
filename: '[name].js',
globalObject: 'globalThis',
path: path.join(__dirname, 'build'),
environment: {
arrowFunction: true,
bigIntLiteral: true,
const: true,
destructuring: true,
dynamicImport: true,
forOf: true,
module: true,
optionalChaining: true,
templateLiteral: true
}
},
performance: {
hints: false
},
optimization: {
minimizer: [
new (require('terser-webpack-plugin'))({
terserOptions: {
compress: {
evaluate: false,
unsafe_Function: false
},
mangle: true,
format: {
comments: false
}
},
extractComments: false
})
]
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser.js'
}),
new webpack.IgnorePlugin({
contextRegExp: /moment$/,
resourceRegExp: /^\.\/locale$/
}),
new webpack.DefinePlugin({
// @pezkuwi/* packageInfo.js reads import.meta.url, which webpack would bake in as
// the absolute file:// path of the machine that built it. That leaks the build
// directory into the published extension and makes the Firefox source build
// (scripts/diff.sh, and AMO's own review) differ from ours. The value is only
// shown in duplicate-version warnings.
'import.meta.url': JSON.stringify('file:///pezkuwi-extension/node_modules/'),
'process.env': {
EXTENSION_PREFIX: JSON.stringify(process.env.EXTENSION_PREFIX || EXT_NAME),
NODE_ENV: JSON.stringify('production'),
PORT_PREFIX: JSON.stringify(blake2AsHex(JSON.stringify(manifest), 64))
}
}),
new CopyPlugin({ patterns: [{ from: 'public' }] }),
new ManifestPlugin({
config: {
base: manifest,
extend: {
version: pkgJson.version.split('-')[0] // remove possible -beta.xx
}
}
})
],
resolve: {
alias: packages.reduce((alias, p) => ({
...alias,
[`@pezkuwi/${p}`]: path.resolve(__dirname, `../${p}/src`)
}), alias),
extensionAlias: {
'.js': ['.ts', '.tsx', '.js']
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify')
}
},
watch: false
});