ES6 and AMD require paths are raw, you can make them mean whatever you want, but by default mean baseUrl+path
. In npm the paths are relative to the file calling require
if the path starts with a directory separater, if there is no separator it looks in node_modules
. For example:
// looks in node_modules
// we'll call this a "vendor require"
var handlebars = require('handlebars');
// looks relative to this file
// we'll call this a "relative require"
var local = require('./handlebars');
There is no such convention in AMD or ES6. Given this ambiguity we will need to be more intelligent with the umd transpilation.
Perhaps we can check the dependencies in package.json
to distinguish between local and vendor requires.
Given this package.json:
{
"dependencies": {
"rsvp": "*"
}
}
The following module code...
import { EventTarget } from 'rsvp/events'
import format from 'time/format'
becomes:
var EventTarget = require('rsvp/events').EventTarget;
var format = require('./time/format');
(amd/global umd code omitted for clarity.)
Because node modules require relative, the transpiler needs to be aware of the current file's path.
Given a file nested two directories from root with the same code:
import { EventTarget } from 'rsvp/events'
import format from 'time/format'
The output becomes:
var EventTarget = require('rsvp/events').EventTarget;
var format = require('../../time/format');
Vendor requires for global modules will not work. All vendor requires must map to an entry in package.json's dependencies
or devDependencies
.
you can just use relative paths with the es6 transpiler & AMD just like you do with CJS modules. RSVP does this: https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp.js