英文:
How can I customize the output filename when multiple inputs?
问题
config
{
input: ['src/index.js', 'src/module1/index.js', 'src/module2/index.js'],
output: {
dir: 'dist',
format: 'es'
}
}
structure
├── dist
│ ├── index.js
│ ├── index2.js
│ └── index3.js
├── rollup.config.js
└── src
├── index.js
├── module1
│ ├── foo.js
│ └── index.js
└── module2
├── bar.js
└── index.js
expect the outputs to be like this
├── dist
│ ├── libname.js
│ └── module
│ ├── module1.js
│ └── module2.js
Is there any option or plugin could help? Thanks a lot!
英文:
config
{
input: ['src/index.js', 'src/module1/index.js', 'src/module2/index.js'],
output: {
dir: 'dist',
format: 'es'
}
}
structure
├── dist
│   ├── index.js
│   ├── index2.js
│   └── index3.js
├── rollup.config.js
└── src
├── index.js
├── module1
│   ├── foo.js
│   └── index.js
└── module2
├── bar.js
└── index.js
expect the outputs to be like this
├── dist
│   ├── libname.js
│   └── module
│   ├── module1.js
│   └── module2.js
Is there any option or plugin could help? Thanks a lot!
答案1
得分: 2
这里是,使用 Vite 测试过的:
https://rollupjs.org/configuration-options/#output-entryfilenames
英文:
Here you go, tested with Vite:
https://rollupjs.org/configuration-options/#output-entryfilenames
import { defineConfig } from 'vite';
import path from 'path';
export default defineConfig(() => {
return {
build: {
rollupOptions: {
input: ['src/index.js', 'src/module1/index.js', 'src/module2/index.js'],
output: {
entryFileNames: chunk => {
if (chunk.facadeModuleId.endsWith('src/index.js')) {
return 'libname.js'
}
if (chunk.facadeModuleId.includes('/module')) {
const dir = path.dirname(chunk.facadeModuleId);
return 'module/' + path.basename(dir) + '.js';
}
}
}
},
},
};
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论