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: v6 - Environment API #16471
base: main
Are you sure you want to change the base?
feat: v6 - Environment API #16471
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Co-authored-by: Vladimir Sheremet <[email protected]> Co-authored-by: Hiroshi Ogawa <[email protected]> Co-authored-by: 翠 / green <[email protected]> Co-authored-by: Jun Shindo <[email protected]> Co-authored-by: Greg T. Wallace <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Caven <[email protected]> Co-authored-by: sapphi-red <[email protected]> Co-authored-by: Matyáš Racek <[email protected]> Co-authored-by: bluwy <[email protected]>
Co-authored-by: Igor Minar <[email protected]> Co-authored-by: Vladimir <[email protected]> Co-authored-by: 翠 / green <[email protected]> Co-authored-by: Clément <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
…in the PR and discussions now
Co-authored-by: patak-dev <[email protected]>
I experimented with It feels really nice to use, so only positive feedback here to confirm if I'm using it right:
|
Yes, I think it makes sense to do it there.
You shouldn't be doing it either for shared plugins. You'll directly use |
Indeed, calling export function vitePluginSharedUnocss(): Plugin {
const ctx = getUnocssContext();
return {
...
create(environment) {
if (environment.mode === "dev") {
ctx.onInvalidate(() => environment.hot.send( .... ));
}
...
}
}
} |
Ah, this makes sense. Then yes, the new |
Co-authored-by: Dario Piotrowicz <[email protected]>
We discussed with @sapphi-red and he proposed we move away from the
After [email protected], instead of function plugin() {
return {
name: 'shared-plugin',
create(environment) {
return {
name: 'bounded-plugin',
transform() { ... }
}
}
}
} we switched to function plugin() {
return (environment) => {
return {
name: 'bounded-plugin',
transform() { ... }
}
}
} @hi-ogawa for the case you were having both a shared plugin hook and create in the same plugin, you can get the same by returning an array: [
{ name: 'shared-plugin', ... },
(environment) => ({ name: 'bounded-plugin', ... }),
] |
/ecosystem-ci run |
/** | ||
* Optimize deps config | ||
*/ | ||
optimizeDeps?: DepOptimizationConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like currently optimizeDeps.entries
is not exposed (entries
is in DepOptimizationOptions
instead of DepOptimizationConfig
). Is this intended?
environments: {
client: {
dev: {
optimizeDeps: {
// this is currently type error
entries: []
},
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand on a good use case for having different entries
? These are only used while scanning, that is currently only enabled for the client
environment. This is now an artificial limitation though. Given that we can properly issue a reload for all environments, we could opt-in into the full scanning + registering missing dependencies instead of a static list if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, what I meant is only for client
environment, just something equivalent of current root optimizeDeps.entries
to help discovering deps early using initial esbuild scan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current config.optimizeDeps.entries
will be used during scan. But I think we should move it to environment options 👍🏼
📝 Ran ecosystem CI on
✅ ladle, laravel, rakkas, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages |
Description
Note
Check out the Environment API Docs
We're starting a new PR for the Environment API work in progress proposal for v6 to have a clean slate for reviews and discussions now that the implementation and docs are more stable.
This PR merges the work done in:
Refer to the discussions in these PRs for context. If you have general feedback about the APIs, let's use this discussion so we can have proper threads:
If you have comments about the implementation or would like to collaborate a feature, fix, test, or docs, please comment in this PR as an usual review or send a PR against the
v6/environment-api
branch.