Last active
March 23, 2018 22:02
-
-
Save btakita/a578cd0a797ae1d04de17dafc0631d27 to your computer and use it in GitHub Desktop.
Resolve from current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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