4

i'm using nwb to create a new library.

using default settings, nwb will use build project to cjs and es6 and umb and include builds in /lib folder

example project structure

-src
  --ModuleA
    --- index.js
    --- helperForA.js
  --ModuleB
    --- index.js
    --- helperForA.js

  index.js
-lib
  --ModuleA
    --- index.js
    --- helperForA.js
  --ModuleB
    --- index.js
    --- helperForA.js

  --index.js
-package.json

now when i install them into another project i cannot access subfolders without adding /lib prefix first

when i npm install my library into another project currently i have to do

import {A} from 'testLibrary/lib/ModuleA'

but what i want is to do

import {A} from 'testLibrary/ModuleA'
Zalaboza
  • 8,899
  • 16
  • 77
  • 142

1 Answers1

1

You can use src/index.js to re-export the contents of your library, as per the Libraries docs:

export A from './ModuleA'
export B from './ModuleB'
Jonny Buchanan
  • 61,926
  • 17
  • 143
  • 150
  • 2
    i do re-export, but does not that mean that user must use `import {A} from 'root'` ? or by re-exporting it automatically enable `import A from 'root/A'` ? – Zalaboza Aug 09 '18 at 06:45