2

I'm having an issue while trying to import all files in one of my directories.

This works:

import '../pages/guidance/target_access_client_relationships.js';

While this doesn't:

import '../pages/guidance';

What am I doing wrong? I am planning to have quite a lot of files in 'guidance' and I'd rather not have to import every single file individually.

Thanks!

gonzo187
  • 35
  • 6

2 Answers2

3

The only way I know is to use a index.js and import all the file inside it.

EX:

dir A index.js

import './fileA.js'
import './fileB.js'

dir B  index.js

import './fileA.js'
import './fileB.js'

and finally you can make a parent dir and import both

parent dir index.js

import './dirB'
import './dirA'
EQuimper
  • 5,811
  • 8
  • 29
  • 42
1

This is not possible I don't think, but what you can do is this...

Create in the directory a index.js file which imports everything from the directory and exports it.

import modules from files in directory has a similar answer.

Community
  • 1
  • 1
Jake Lacey
  • 623
  • 7
  • 24
  • Thanks for the hint with the exports. I'll go with Emanuel Quimper's way, but I'll definitely save this for later – gonzo187 Jun 29 '16 at 10:47