简体   繁体   English

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

[英]rollup.js how to import additional files without changing source files

my example is based on the rollup.js basic example: https://rollupjs.org/guide/en/#rolluprollup我的示例基于 rollup.js 基本示例: https://rollupjs.org/guide/en/#rolluprollup

the project i am working on require additional files to be included and excluded.我正在处理的项目需要包含和排除其他文件。 (i know how to exclude path's using 'rollup-plugin-ignore' plugin.) (我知道如何使用“rollup-plugin-ignore”插件排除路径。)

how can i tell rollup.js to add files to the import list (same as i was importing them in the source code), without changing the source files.我如何告诉 rollup.js 将文件添加到导入列表(就像我在源代码中导入它们一样),而不更改源文件。 ? ?

i tried to commonjs plugin我尝试了 commonjs 插件

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

but i don't see the 'FormLogin' component in the output file.但我在 output 文件中看不到“FormLogin”组件。

is there a more simple way, can you help me please?有没有更简单的方法,你能帮我吗?

i will appreciate your help.我会感谢你的帮助。
thank you very much.非常感谢您。

Thats a little bit unorthodox because rollup.js uses tree-shaking to analyse your code and only include the used parts and you want something included which isnt used.这有点不正统,因为 rollup.js 使用 tree-shaking 来分析您的代码,并且只包含使用过的部分,而您想要包含未使用的部分。

the easist way would be concatenation on the command line, like in windows cmd:最简单的方法是在命令行上连接,例如 windows cmd:

type file_from_rollup.js additional.js > bundle.js

second, you could instruct rollup to use two entry points:其次,您可以指示汇总使用两个入口点:

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

this will generate two bundled files in the./bundle folder, both of them tree-shaked这将在 ./bundle 文件夹中生成两个捆绑文件,它们都是经过摇树的

If the FormLogin.jsx is referenced in the source code (seen from the main entry point) try to disable tree shaking like如果在源代码中引用了 FormLogin.jsx(从主入口点看),请尝试禁用树抖动,例如

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

and see if its included.看看它是否包括在内。 Maybe rollup.js doesnt recognize it corretly: https://rollupjs.org/guide/en/#tree-shaking-doesnt-seem-to-be-working也许 rollup.js 不能正确识别它: https://rollupjs.org/guide/en/#tree-shaking-doesnt-seem-to-be-working

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用rollup.js将javascript文件与一个外部库捆绑在一起? - How to bundle javascript files with one external library with rollup.js? Rollup.js如何在没有任何更改的情况下导入js文件(不是es6模块)(myvar $ extrastring) - Rollup.js how import a js file (not es6 module) without any change (myvar$extrastring) 在 Rollup.js 中导入 static 个文件的整个目录 - Importing a whole directory of static files in Rollup.js 如何仅在 Rollup.js 编译时获取一个文件夹的文件列表? - How to get files list of one folder only at the Rollup.js compile time? rollup.js单个导入多个用法 - rollup.js single import multiple usages 什么是.esm.js文件和什么格式:rollup.js中的'es'? - what are .esm.js files and whats with the format: 'es' in rollup.js? 如何在 Rollup.js 中清除缓存? - How to do cache busting in Rollup.js? 如何使用Rollup.JS写入文件 - How to write to file with Rollup.JS Rollup.js - 让 PostCSS 处理整个 bundle.css 而不是来自 rollup-plugin-svelte 的单个文件 - Rollup.js - have PostCSS process whole bundle.css instead of individual files from rollup-plugin-svelte 如何在 Rollup.js 中将依赖 package 的导入模块更改为替换该模块的本地文件? - How can I change in Rollup.js an import module of a dependency package to a local file replacing that module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM