When configuring Rollupjs to generate a library, if the input is an array which consists of multiple javascript files. How can we do to these inputs will be generated in just a single output js file?
当配置Rollupjs以生成库时,如果输入是一个由多个Java脚本文件组成的数组。我们怎么做才能将这些输入只生成一个输出js文件呢?
export const lgService = {
input: [
'./src/app/services/livegiver/lgservices.js',
'./src/app/services/readable-stream.js'
],
output: {
file: outputPath + 'LiveGiver/index.js',
format: 'es'
}
}
Expected:
预期:
Input: [a.js, b.js]
Output: dist/index.js
Actual:
实际:
Input: [a.js, b.js]
Output: dist/a.js; dist/b.js
更多回答
优秀答案推荐
You can't — multiple inputs implies multiple outputs. To do what you're describing, you'll need to have a single entry module that looks something like this:
你不能--多个输入意味着多个输出。要完成您所描述的操作,您需要有一个类似于以下内容的单一入口模块:
import './app/services/livegiver/lgservices.js';
import './app/services/readable-stream.js';
If you need to generate that module dynamically you could use something like rollup-plugin-virtual.
如果需要动态生成该模块,可以使用ROLLUP-PUGIN-VIRTUAL。
You can import all your js files into index.js.
and export from index.js like the below
您可以将所有js文件导入到index.js中。并从index.js导出,如下所示
export { default as YourComponent} from "component path";
then in your rollup.config.js file.
然后在您的Rolup.config.js文件中。
export const lgService = {
input: './src/app/index.js',
output: {
file: outputPath + '/index.js',
}
}
this is tested in rollup v2.57.0
这在ROLLUP v2.57.0中进行了测试
更多回答
我是一名优秀的程序员,十分优秀!