Skip to content

Commit

Permalink
fix: transpile dynamic imports for cjs to require
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Dec 19, 2022
1 parent 88a3b16 commit 5a62235
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 111 deletions.
122 changes: 19 additions & 103 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 @@ -45,7 +45,6 @@
"@commitlint/config-conventional": "^17.3.0",
"@commitlint/cz-commitlint": "^17.3.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^23.0.5",
"@rollup/plugin-node-resolve": "^15.0.0",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/commit-analyzer": "^9.0.2",
Expand All @@ -59,6 +58,7 @@
"@types/jest": "^27.5.0",
"@types/node": "^18.11.17",
"@types/yargs": "^17.0.17",
"babel-plugin-dynamic-import-node": "^2.3.3",
"coveralls": "^3.1.0",
"cross-env": "^7.0.3",
"eslint": "^8.30.0",
Expand Down
40 changes: 33 additions & 7 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* view the LICENSE file that was distributed with this source code.
*/

import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import pkg from './package.json' assert { type: 'json' };
Expand All @@ -29,9 +28,6 @@ export default [
// Allows node_modules resolution
resolve({ extensions }),

// Allow bundling cjs modules. Rollup doesn't understand cjs
commonjs(),

// Compile TypeScript/JavaScript files
babel({
extensions,
Expand All @@ -43,12 +39,42 @@ export default [
],
output: [
{
file: pkg.main,
format: 'cjs'
}, {
file: pkg.module,
format: 'esm',
},
],
},
{
input: './src/index.ts',

// Specify here external modules which you don't want to include in your bundle (for instance: 'lodash', 'moment' etc.)
// https://rollupjs.org/guide/en/#external
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],

plugins: [
// Allows node_modules resolution
resolve({ extensions }),

// Compile TypeScript/JavaScript files
babel({
extensions,
babelHelpers: 'bundled',
include: [
'src/**/*',
],
plugins: [
"dynamic-import-node"
]
})
],
output: [
{
file: pkg.main,
format: 'cjs'
}
],
},
];

0 comments on commit 5a62235

Please sign in to comment.