How to bundle require statements from esm?
tornadocontrib opened this issue · 3 comments
Hello,
I would like to know how to make the rollup bundle packages imported by require statement from esm.
For example,
// test.mjs
import test from 'test'
const some_module = require('some');
would leave
// output.js
const some_module = require('some');
like this so the package imported by require statement isn't bundled
How should I force it to bundle?
Thanks,
You need @rollup/plugin-commonjs. If you want to use both include
and require
statement in the same file, set transformMixedEsModules to true
. Example rollup config file:
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [commonjs({
transformMixedEsModules: true
})]
};
@liuly0322 Have tried but still it wouldn't bundle modules imported by require statement
@liuly0322 Have tried but still it wouldn't bundle modules imported by require statement
Check the config file usage, are you using -c
option (for example npx rollup -c
or add -c
option in your package.json
scripts)? If that doesn't work, would you please provide a minimal reproducible example repo and the command you use to bundle?