简体   繁体   中英

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
   |- 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
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM