【问题标题】:How to load all files in a subdirectories using rollup without require statements如何在不使用 require 语句的情况下使用汇总加载子目录中的所有文件
【发布时间】:2018-04-20 01:19:28
【问题描述】:

我在 src/ 中有大量的 javascript 文件,我不想手动进入并要求我所有的文件。

|- /src
   |- a.js
   |- b.js
   |- c.js
   |- more.js
   | - index.js

index.js

import a from 'a.js'
import a from 'b.js'
import a from 'c.js'
//import more

export default {
  a,
  b,
  c,
  // more
}

有没有办法通过汇总或某人编写的插件来做到这一点?

英语不是我的母语;请原谅打字错误。

【问题讨论】:

标签: javascript node.js web rollup rollupjs


【解决方案1】:

当你导出一个模块时,它会自动导入,所以你可以这样做:

export * from 'a.js';
export * from 'b.js';
// ...

如果您以后不需要导入这些模块,只需将它们包含在包中,您可以像这样导入它们:

import 'a.js';
import 'b.js';

等等。

你也可以看看https://www.npmjs.com/package/rollup-plugin-glob-import

【讨论】:

    猜你喜欢
    • 2015-06-07
    • 2018-10-09
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多