![](/img/trans.png)
[英]How to bundle javascript files with one external library with rollup.js?
[英]rollup.js how to import additional files without changing source files
我的示例基於 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})
但我在 output 文件中看不到“FormLogin”組件。
有沒有更簡單的方法,你能幫我嗎?
我會感謝你的幫助。
非常感謝您。
這有點不正統,因為 rollup.js 使用 tree-shaking 來分析您的代碼,並且只包含使用過的部分,而您想要包含未使用的部分。
最簡單的方法是在命令行上連接,例如 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.