You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a couple of places where I'd like to be able to call resolveId from a plugin. One such place is the handlebars.js plugin (see jibhaine/rollup-plugin-handlebars#2), and another is in rollup-plugin-root-import (see mixmaxhq/rollup-plugin-root-import#1).
In the former case, I'd like to be able to resolve the paths used to reference partials (handlebars imports), because handlebars uses its own mechanism for linking templates and partials. Handlebars generally works by providing a registerPartial method, and partial invocations use the internal map of partials. A more ideal solution would involve explicitly passing dependencies to each handlebars template, but that would break interoperability with conventional handlebars usage.
In the latter case, with root-import, I really only need access to the entryId, as that's what would enable cleaner default behavior, but a more general solution would involve exposing the ability to run resolveId from the plugin itself:
import{rollup}from'rollup';importrootImportfrom'rollup-plugin-root-import';// ideal usagerollup.rollup({// absolute paths would be resolved relative to thisentry: 'src/index.js'plugins: [rootImport]}).then(...);// current usagerollup.rollup({entry: 'src/index.js',plugins: [rootImport({// currently needs this to resolve accuratelyroot: `${__dirname}/src`})]}).then(...);
Without this functionality, rootImport would need to be explicitly passed its root
Thoughts? Maybe there's a way to accomplish these goals without introducing weird coupling behavior?
I would like to write a babel plugin which rewrites package imports to use src files instead of compiled (dist) files, similar to babel-plugin-lodash.
Bundle would provide access to entryModule.exports and entryModule.exportsAll mappings that could be used to generate a manifest file required for such a plugin.
@Rich-Harris
In my case, I would like to get access to the instance of the Bundle class.
Maybe it can be the second argument passed to the promise resolve function or a property of the result.
rollup(options).then((result, bundle) => {...})
I managed to solve my problem using rollup-plugin-babel and a custom Babel plugin, so it's fine if you decide not to make any changes.
@mstijak giving plugins access to internal implementation details is one of those things that sounds harmless at the time but almost always ends up being a mistake, because as soon as that happens you've basically made it part of the API, and a seemingly minor refactor in a patch release can have far-reaching breaking changes that are impossible to anticipate.
If we were to expose any additional functionality it would have to be done so explicitly, with documentation and tests.
Activity
mstijak commentedon Dec 7, 2016
I would like to write a babel plugin which rewrites package imports to use src files instead of compiled (dist) files, similar to babel-plugin-lodash.
Bundle would provide access to
entryModule.exportsandentryModule.exportsAllmappings that could be used to generate a manifest file required for such a plugin.Rich-Harris commentedon Jan 6, 2017
Sorry for slow reply. Can you be more specific about what APIs you would need to accomplish these tasks?
FYI you can pass an
optionshook to intercept and manipulate options:mstijak commentedon Jan 7, 2017
@Rich-Harris
In my case, I would like to get access to the instance of the Bundle class.
Maybe it can be the second argument passed to the promise resolve function or a property of the result.
I managed to solve my problem using
rollup-plugin-babeland a custom Babel plugin, so it's fine if you decide not to make any changes.Rich-Harris commentedon Jan 7, 2017
@mstijak giving plugins access to internal implementation details is one of those things that sounds harmless at the time but almost always ends up being a mistake, because as soon as that happens you've basically made it part of the API, and a seemingly minor refactor in a patch release can have far-reaching breaking changes that are impossible to anticipate.
If we were to expose any additional functionality it would have to be done so explicitly, with documentation and tests.
guybedford commentedon Jun 6, 2018
This has been opened up in #2208. Feedback welcome.