activewidgets / getlibs

OBSOLETE, DO NOT USE: This project is no longer maintained
MIT License
165 stars 12 forks source link

Import/require unbundled packages #4

Closed json2d closed 7 years ago

json2d commented 7 years ago

Seems like I can only import packages from npm that bundle the entire main module into a single file. Is there a plan on the roadmap to support importing unbundled packages with many loose files?

xkam commented 7 years ago

It depends on the package configuration - for example, with lodash you can import individual modules as well - https://github.com/activewidgets/getlibs/blob/master/examples/lodash/es6/hello/hello.js#L2

getlibs is based on systemjs, so you can add your own configuration as well (see #2).

Do you have in mind any particular npm package?

json2d commented 7 years ago

So in my example, getlibs is trying to import/require cwise-compiler, but when it encounters a local module within that module's source...

var createThunk = require("./lib/thunk.js")

...systemjs trys to resolve it as if it were a module from npm:

system.src.js:80 Uncaught (in promise) Error: Fetch error: 404 
  Instantiating https://unpkg.com/lib/thunk.js
  Loading https://unpkg.com/cwise-compiler

As you've said though, this seems more of an issue for systemjs

xkam commented 7 years ago

You can try adding a mapping with a full path to systemjs config -

System.config({
    map: {
        'cwise-compiler': 'https://unpkg.com/cwise-compiler/compiler.js'
    }
});

It should fix relative imports.

json2d commented 7 years ago

Thanks that works!