rollup.js如何在不更改源文件的情况下导入其他文件

问题描述 投票:0回答:1

我的示例基于rollup.js基本示例:https://rollupjs.org/guide/en/#rolluprollup

我正在从事的项目要求包含和排除其他文件。 (我知道如何使用“ rollup-plugin-ignore”插件排除路径。)

我如何告诉rollup.js将文件添加到导入列表(与我在源代码中导入文件相同),而无需更改源文件。 ?

我尝试使用commonjs插件

var commonjs = require('rollup-plugin-commonjs');
var include = ["D:\\...abs_path....\\components\\Auth\\FormLogin.jsx"]
commonjs( {"include": include})

但是我在输出文件中看不到'FormLogin'组件。

有没有更简单的方法,请您能帮我吗?

我将感谢您的帮助。非常感谢你。

javascript rollupjs
1个回答
0
投票

这有点不合常规,因为rollup.js使用摇树来分析您的代码,并且只包含使用过的部分,并且您希望包含不使用的部分。

简单的方法是在命令行上进行串联,就像在Windows cmd中一样:

type file_from_rollup.js additional.js > bundle.js

第二,您可以指示汇总使用两个入口点:

rollup main.js libB.js -d ./bundle --format cjs

这将在./bundle文件夹中生成两个捆绑文件,它们都被树状摇动

如果在源代码中引用了FormLogin.jsx(从主入口点看到,请尝试禁用树抖动,如]

rollup main.js --no-treeshake  --file bundle.js --format cjs

并查看其是否包含在内。也许rollup.js无法正确识别它:https://rollupjs.org/guide/en/#tree-shaking-doesnt-seem-to-be-working

© www.soinside.com 2019 - 2024. All rights reserved.