mirror of
https://github.com/pezkuwichain/pezkuwi-extension.git
synced 2026-04-22 06:47:58 +00:00
7e586239ae
- New Firefox extension ID for AMO - Fixed data_collection_permissions for Mozilla compliance - Updated webpack config for ES2022 target - Added firefox-postprocess.sh script - Bumped all packages to 0.62.18
156 lines
3.8 KiB
JavaScript
156 lines
3.8 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({
|
|
'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: {
|
|
crypto: require.resolve('crypto-browserify'),
|
|
path: require.resolve('path-browserify'),
|
|
stream: require.resolve('stream-browserify')
|
|
}
|
|
},
|
|
watch: false
|
|
});
|