简体   繁体   English

如何在不使用require语句的情况下使用汇总加载子目录中的所有文件

[英]How to load all files in a subdirectories using rollup without require statements

I have a large amount of javascript files in src/, I don't want to manually go in and require all my files. 我在src /中有大量的javascript文件,我不想手动输入所有文件。

|- /src
   |- a.js
   |- b.js
   |- c.js
   |- more.js
   | - index.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
}

Is there a way to do this with rollup or a plugin that someone has written to do this? 有没有办法使用汇总或有人编写的插件来做到这一点?

English is not my native language; 英语不是我的母语。 please excuse typing errors. 请原谅输入错误。

When you export a module it is automatically imported, so you can do: 导出模块时,它会自动导入,因此您可以执行以下操作:

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

If you don't need to import those modules later, but just include them in the bundle, you can import them like this: 如果您以后不需要导入那些模块,而只是将它们包括在捆绑软件中,则可以这样导入它们:

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

And so on. 等等。

You can also take a look at https://www.npmjs.com/package/rollup-plugin-glob-import . 您也可以查看https://www.npmjs.com/package/rollup-plugin-glob-import

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

相关问题 如何在没有require语句的情况下使用webpack加载目录中的所有文件 - How to load all files in a directory using webpack without require statements 如何使用汇总在包中同时包含 import 和 require 语句 - How to include both import and require statements in the bundle using rollup 使用require-all从目录和子目录递归加载文件 - Recursively load files from directory and subdirectories with require-all 如何使用 nodeJS 列出所有子目录和文件? - How to list all subdirectories and files using nodeJS? 有没有办法在使用 Rollup 时删除不必要的 'require(...)'/'import "..."' 语句 - Is there a way to remove unnecessary 'require(...)'/'import "..."' statements when using Rollup 如何使用HTTPS(而非HTTP)require.js加载JavaScript文件? - How to load JavaScript files using HTTPS (and not HTTP) require.js? TSC/Rollup:如何在没有 TSC 发出文件的情况下将 pipe TSC output 放入 Rollup? - TSC/Rollup: how to pipe TSC output into Rollup without TSC emitting files? 使用Browserify将所有require('backbone')语句解析到同一位置 - Have all require('backbone') statements resolve to the same place using Browserify 如何让 Rollup 转换 require() 调用? - How to get Rollup to transform require() calls? 如何使用php加载extjs所需文件? - how to load extjs require files with php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM