Skip to content

Commit

Permalink
fix: split chunk only for firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
hz002 committed Oct 17, 2024
1 parent b3b899b commit 3b33de7
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions build/webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const BUILD_GIT_HASH = child_process
const MANIFEST_TYPE = process.env.MANIFEST_TYPE || 'chrome-mv2';
const IS_MANIFEST_MV3 = MANIFEST_TYPE.includes('-mv3');
const FINAL_DIST = IS_MANIFEST_MV3 ? paths.dist : paths.distMv2;
const IS_FIREFOX = MANIFEST_TYPE.includes('firefox');

const config = {
entry: {
Expand Down Expand Up @@ -216,7 +217,9 @@ const config = {
new HtmlWebpackPlugin({
inject: true,
template: paths.backgroundHtml,
chunks: ['background', 'bg-chunk1', 'bg-chunk2', 'bg-chunk3'],
chunks: ['background'].concat(
IS_FIREFOX ? ['bg-chunk1', 'bg-chunk2', 'bg-chunk3'] : []
),
filename: 'background.html',
}),
new HtmlWebpackPlugin({
Expand All @@ -240,7 +243,9 @@ const config = {
patterns: [
{ from: paths.rootResolve('_raw'), to: FINAL_DIST },
{
from: paths.rootResolve(`src/manifest/${MANIFEST_TYPE}/manifest.json`),
from: paths.rootResolve(
`src/manifest/${MANIFEST_TYPE}/manifest.json`
),
to: FINAL_DIST,
},
IS_MANIFEST_MV3
Expand All @@ -249,32 +254,36 @@ const config = {
'@trezor/connect-webextension/build/content-script.js'
),
to: path.resolve(
FINAL_DIST, './vendor/trezor/trezor-content-script.js'
FINAL_DIST,
'./vendor/trezor/trezor-content-script.js'
),
}
: {
from: require.resolve(
'@trezor/connect-web/lib/webextension/trezor-content-script.js'
),
to: path.resolve(
FINAL_DIST, './vendor/trezor/trezor-content-script.js'
FINAL_DIST,
'./vendor/trezor/trezor-content-script.js'
),
},
IS_MANIFEST_MV3
IS_MANIFEST_MV3
? {
from: require.resolve(
'@trezor/connect-webextension/build/trezor-connect-webextension.js'
),
to: path.resolve(
FINAL_DIST, './vendor/trezor/trezor-connect-webextension.js'
FINAL_DIST,
'./vendor/trezor/trezor-connect-webextension.js'
),
}
: {
from: require.resolve(
'@trezor/connect-web/lib/webextension/trezor-usb-permissions.js'
),
to: path.resolve(
FINAL_DIST, './vendor/trezor/trezor-usb-permissions.js'
FINAL_DIST,
'./vendor/trezor/trezor-usb-permissions.js'
),
},
],
Expand Down Expand Up @@ -306,24 +315,26 @@ const config = {
name: 'webextension-polyfill',
chunks: 'all',
},
bgChunk1: {
test: /[\\/]node_modules[\\/](@rabby-wallet|ethers|@ethersproject|@chainsafe|@trezor|@safe-global|@walletconnect)[\\/]/,
name: 'bg-chunk1',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
bgChunk2: {
test: /[\\/]node_modules[\\/](@keystonehq|@eth-optimism|@coinbase|gridplus-sdk)[\\/]/,
name: 'bg-chunk2',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
bgChunk3: {
test: /[\\/]node_modules[\\/](@imkey|@onekeyfe|@ethereumjs|viem|@metamask)[\\/]/,
name: 'bg-chunk3',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
...(IS_FIREFOX && {
bgChunk1: {
test: /[\\/]node_modules[\\/](@rabby-wallet|ethers|@ethersproject|@chainsafe|@trezor|@safe-global|@walletconnect)[\\/]/,
name: 'bg-chunk1',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
bgChunk2: {
test: /[\\/]node_modules[\\/](@keystonehq|@eth-optimism|@coinbase|gridplus-sdk)[\\/]/,
name: 'bg-chunk2',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
bgChunk3: {
test: /[\\/]node_modules[\\/](@imkey|@onekeyfe|@ethereumjs|viem|@metamask)[\\/]/,
name: 'bg-chunk3',
chunks: (chunk) => chunk.name === 'background',
minSize: 0,
},
}),
uiVender: {
test: /[\\/]node_modules[\\/]/,
name: 'ui-vender',
Expand Down

0 comments on commit 3b33de7

Please sign in to comment.