Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose --experimental-loader API inside plugins #699

Open
vjpr opened this issue Oct 22, 2021 · 0 comments
Open

Expose --experimental-loader API inside plugins #699

vjpr opened this issue Oct 22, 2021 · 0 comments

Comments

@vjpr
Copy link

vjpr commented Oct 22, 2021

Issue description or question

Related: #696 (comment)

Plugins like https://github.com/Nodman/quokka-plugin-subdir are not possible in ESM environments without access to it.

Would be nice to allow hooking into this via the plugin API.

Alternative

Support subdir functionality in Quokka's hook.

Allow specifying the context.parentURL to use in the Loader.resolve hook from a plugin API.

module.exports = {
  before: async (config, setProjectDir) => { 
     const {pkgDir, pkg} = config
     // Also, allow user to locate the `pkgDir` from the package name (`pkg`) themselves.
    setProjectDir(pkgDir)
  }
}
({
  pkg: '@foo/bar',
})

// quokka scratch file

When I add my own experimental loader, Quokka adds theirs to the end:

  env: { params: { runner: '--experimental-loader=file:///my/esm-loader-wallaby.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --experimental-vm-modules --experimental-top-level-await --experimental-loader "file:///Users/Vaughan/Library/Application%20Support/JetBrains/IntelliJIdeaVaughan/config/plugins/quokka-intellij/dist/runners/node/quokka@1.0.0/hooks.mjs"' } }

Otherwise, you could just add your loader and import Quokka's loader.

Chaining hooks is coming to Node.js soon - still in development which would solve this.


FYI, the hook api was recently changed too.

Note: In a previous version of this API, this was split across 3 separate, now deprecated, hooks (getFormat, getSource, and transformSource).
https://nodejs.org/api/esm.html#loadurl-context-defaultload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants