Skip to content

Commit

Permalink
Fixed a preserve modules bundling issue with rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
matux committed Mar 8, 2024
1 parent 8ca121d commit 77b6fc7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 59 deletions.
112 changes: 56 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"regenerator-runtime": "^0.14.1",
"rimraf": "^5.0.5",
"rollbar": "^2.26.3",
"rollup": "^4.12.0",
"rollup": "^4.12.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-directives": "^0.4.0",
"ts-jest": "^29.1.2",
Expand Down
14 changes: 12 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const COMMON_PLUGINS = [
babel({ babelHelpers: 'bundled', exclude: ['node_modules/**'] }),
];

const entryFileNames = (chunkInfo) => {
if (chunkInfo.name.includes('node_modules')) {
return chunkInfo.name.replace(/node_modules/g, 'external') + '.js';
}

return '[name].js';
};

const onwarn = (warning, warn) => {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return;
Expand Down Expand Up @@ -61,16 +69,18 @@ export default [
dir: pkg.module,
format: 'es',
sourcemap: true,
entryFileNames: '[name].js',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames,
},
{
dir: pkg.main,
format: 'cjs',
sourcemap: true,
entryFileNames: '[name].js',
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames,
},
],
plugins: [
Expand Down

0 comments on commit 77b6fc7

Please sign in to comment.