Closed xlslucky closed 3 years ago
Hi @xlslucky,
This is due to how Rollup's preserveModules
option works, has nothing to do with this plugin.
It's explained in this comment:
The folder is created because preserveModules is preserving the original file names and directory structure. It does not understand that node_modules is something special, though. Also, all exports are rewritten in a way that does not depend on Node's dependency resolution algorithm.
You can solve it using 2 plugins + 1 extra configuration :)
As for configuration, you will need to add this on your output: preserveModulesRoot: 'src',
an example:
import replace from '@rollup/plugin-replace';
import rename from 'rollup-plugin-rename';
export default {
input: 'src/index.ts',
output: [
{
dir: 'dist',
format: 'cjs',
exports: 'named',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
{
dir: 'dist',
format: 'es',
exports: 'named',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
},
],
// your configuration
plugins: [
// your other plugins
rename({
include: ['**/*.js', '**/*.mjs'],
map: (name) => name.replace('node_modules/', 'external/'),
}),
replace({
values: {
'node_modules/': 'external/'
},
delimiters: ['', '']
})
],
}
@prma85 thank you very much. But in my project, I need to simply modify the configuration of the replace plugin
replace({
values: {
'../node_modules/': '../external/',
},
// ...
}),
dist
after buildI expect to get
What should I do?