配置
\n {\n input: ['src/index.js', 'src/module1/index.js', 'src/module2/index.js'],\n output: {\n dir: 'dist',\n format: 'es'\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n结构
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dist\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index2.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index3.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 rollup.config.js\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module1\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo.js\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 module2\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index.js\nRun Code Online (Sandbox Code Playgroud)\n期望输出是这样的
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dist\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 libname.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 module\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module1.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 module2.js\nRun Code Online (Sandbox Code Playgroud)\n有什么选项或插件可以提供帮助吗?多谢!
\n在这里,您已经使用 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';
}
}
}
},
},
};
});
Run Code Online (Sandbox Code Playgroud)