Skip to content

Instantly share code, notes, and snippets.

@btakita
Last active March 23, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btakita/a578cd0a797ae1d04de17dafc0631d27 to your computer and use it in GitHub Desktop.
Save btakita/a578cd0a797ae1d04de17dafc0631d27 to your computer and use it in GitHub Desktop.
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