Skip to content

Instantly share code, notes, and snippets.

@btakita btakita/resolve__rollup.js
Last active Mar 23, 2018

Embed
What would you like to do?
Resolve from current directory
/** Add this into the rollup plugins array
resolve__rollup({
paths: ['.', 'node_modules'],
extensions: ['.mjs', '.js', '.json', '.tag']
})
*/
function resolve__rollup(options) {
return {
name: 'resolve__rollup',
resolveId: $resolveId(options)
}
}
function $resolveId(options) {
const externals =
options.externals
|| []
return resolveId
function resolveId(id, origin) {
let path = id
const path__split = path.split('/')
, path0 = path__split[0]
if (externals.indexOf(path0) !== -1) {
return null
}
if (_builtinLibs.indexOf(path0) !== -1) {
return null
}
if (path.slice(0, 1) === '.') {
const dirname =
origin
&& $path.dirname(origin)
if (dirname) {
path = $path.join(dirname, id)
}
else {
return null
}
}
return resolve.sync(
path,
{ basedir: process.cwd(),
paths: [process.cwd()],
extensions: ['.mjs', '.js']})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.