Skip to content

Commit

Permalink
feat(rollup.config): enhance chunk name generation for pnpm
Browse files Browse the repository at this point in the history
This commit improves the chunk name generation logic in rollup.config.js
to handle nested node_modules directories as created by pnpm. It now
differentiates between regular npm and pnpm structures, providing
appropriate chunk names for both. Also, added a console.table for
debugging purposes to compare before and after chunk names.
  • Loading branch information
ryoppippi committed Jul 2, 2024
1 parent 54779c5 commit 95a2bff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ module.exports = {
const externalDir = `_external`;
const nodeModulesDir = `node_modules`;
if (chunkInfo.name.includes(nodeModulesDir)) {
console.log(chunkInfo.name);
return `${chunkInfo.name.replace(nodeModulesDir, externalDir)}.${ext}`;
const chunkName = chunkInfo.name.includes('.pnpm')
? chunkInfo.name.replace(/(node_modules\/.*?node_modules\/)/, externalDir) // for nested node_modules like pnpm does
: chunkInfo.name .replace(nodeModulesDir, externalDir) // for regular node_modules like npm does
console.table({
before: chunkInfo.name,
after: chunkName,
})
return `${chunkName}.${ext}`;
}
return `[name].${ext}`;
},
Expand Down

0 comments on commit 95a2bff

Please sign in to comment.