I wasn't able to find any discussion on this ~ just an unanswered SO question.
It would be nice if the external config could accept regex or glob patterns. My use case is importing modules within a package, such as lodash-es/isMatch.
I'm adding all of my dependencies to my external config by just mapping out the keys from my package.json dependencies:
import typescript from 'rollup-plugin-typescript2'
import pkg from './package.json'
export default {
input: 'src/index.ts',
output: [{ file: pkg.main, format: 'cjs' }, { file: pkg.module, format: 'es' }],
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependnencies || {})],
plugins: [
typescript({
typescript: require('typescript'),
}),
],
}
But I need to manually add all of my package/something imports.
Or, simpler, if I'm already have lodash-es as an external, it shouldn't warn me about `lodash-es/isMatch.
Also, I haven't dug around in my exports enough to know if lodash-es/isMatch is being included --- I'm just trying to clear out all of these warnings in my output.
Accept glob patterns in external:
external: ['rxjs/**', 'lodash-es/**']
You could also just use a function:
external(id) {
return id.includes('node_modules');
}
Of course this will only work if you do not want some devDependencies to be bundled. In that case, a little more work is necessary:
external(id) {
return Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependnencies || {})).includes(id.split('/')[0]);
}
For a slight performance boost, you could extract the constant Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependnencies || {}) as this function will be called a lot.
Also check out the SO post, I added a slightly longer answer there.
That'll do it, thank you! I'd consider this closed for what I need.
Most helpful comment
Also check out the SO post, I added a slightly longer answer there.