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

feat: expose moduleRewrite and compileSFCStyle #104

Merged
merged 4 commits into from
May 9, 2020

Conversation

pikax
Copy link
Contributor

@pikax pikax commented May 9, 2020

Exposing moduleRewrite and compileSFCStyle for plugin creators

@yyx990803
Copy link
Member

This doesn't add it to the main index.ts exports

@pikax
Copy link
Contributor Author

pikax commented May 9, 2020

That's because currently because we use tsc to compile, I can import from dist/server/serverPluginModuleRewrite.js, but if we bundle we need to add to index.

I will add to index

@pikax pikax changed the title feat: expose moduleRewrite feat: expose moduleRewrite and compileSFCStyle May 9, 2020
@@ -13,6 +13,8 @@ import { assetPathPlugin } from './serverPluginAssets'
import { esbuildPlugin } from './serverPluginEsbuild'

export { Resolver }
export { rewriteImports } from './serverPluginModuleRewrite'
export { compileSFCStyle } from './serverPluginVue'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm writing a plugin to do SSR based on a route, for that I need to parse the SFC file and build a script similar to what vite does. But vite relies on the middleware and the request path to retrieve the cached files or to parse a new file.

Being able to access the internals would be really useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency's sake, I think we either expose all compileSFC* methods or we expose none of them. However, making them public means we can't treat them as internals and freely tweak arguments anymore. They are also assuming to be only used in the dev-server, so it may at some time expect a Koa context - which would make them unusable elsewhere. I think for now it's safer to just copy-paste the logic in your plugin until it's more stable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, in my case I only need the Style, the others I basically copied the logic over.

Is the rewriteImports good to expose?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, rewriteImports is probably safe, although I'd consider it semi-internal for now. You should be prepared if it breaks ;)

@yyx990803 yyx990803 merged commit d6151bf into vitejs:master May 9, 2020
@pikax pikax deleted the feat/export_module_rewrite branch May 9, 2020 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants