gpt4 book ai didi

How to configure in Rollup that will generate only single output file from multiple input files?(如何在汇总中配置从多个输入文件中仅生成单个输出文件?)

转载 作者:bug小助手 更新时间:2023-10-25 16:27:42 24 4
gpt4 key购买 nike



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中进行了测试


更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com