feat: add Vite plugin to Netlify adapter#13768
Conversation
🦋 Changeset detectedLatest commit: 147b2ab The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Cool! What happens if a user runs it via the Netlify CLI? Will it end up running both? Maybe it should be conditionally loaded in that case |
Good point! We should be able to use environment variables to detect whether we're running inside the Netlify CLI and make it a no-op in that case. I just need to think of the best place to check that. |
|
Updated in 0630323 via netlify/primitives#181. |
|
Take a look at this for an example of running dev mode tests: https://github.com/withastro/astro/blob/main/packages/astro/test/sessions.test.js#L135 |
|
@eduardoboucas now the plugin is no longer experimental, do you want to finish off the PR and get this merged? |
Yes! I've just updated the version of the plugin and added some tests. I'm sure there's lots more we can do to make the integration even nicer, but I think this would be a good first step. Let me know your thoughts! |
| adapter: netlify({ | ||
| edgeMiddleware: process.env.EDGE_MIDDLEWARE === 'true', | ||
| imageCDN: process.env.DISABLE_IMAGE_CDN ? false : undefined, | ||
| }), |
There was a problem hiding this comment.
nit: AFAICT from spelunking these are unused here
| adapter: netlify({ | |
| edgeMiddleware: process.env.EDGE_MIDDLEWARE === 'true', | |
| imageCDN: process.env.DISABLE_IMAGE_CDN ? false : undefined, | |
| }), | |
| adapter: netlify(), |
| @@ -0,0 +1,2 @@ | |||
| # Local Netlify folder | |||
There was a problem hiding this comment.
I think this is in the wrong place
packages/integrations/netlify/test/development/primitives.test.js
Outdated
Show resolved
Hide resolved
ascorbic
left a comment
There was a problem hiding this comment.
Thanks! There are a few places in the adapter code where we check if we're running in the Netlify CLI before enabling/disabling various options. e.g. when it's not running in the Netlify CLI, we don't use the image CDN or blobs. These checks should be removed so we can use the primitives in dev.
packages/integrations/netlify/test/development/fixtures/primitives/package.json
Show resolved
Hide resolved
|
The tests are timing-out because they're never exiting. I'm not sure why, because it is stopping the dev server. Did this happen for you when you ran them locally? |
ascorbic
left a comment
There was a problem hiding this comment.
It looks like something isn't being cleaned-up, meaning Node never exits. Presumably one of the Netlify servers? Is there a way we can ensure that they all shut down when the parent dev server exits?
It's possible that this branch was created from an outdated |
|
The hanging tests were caused by an issue on our side, which I have fixed in netlify/primitives#310. I'm expecting them to pass now. ⏳ |
ematipico
left a comment
There was a problem hiding this comment.
Thank you @eduardoboucas, for the PR. Fortuantely the code changes are minimal, which they seem good. However, I have some concerns regarding docs and expectations. Could you clarify them?
| }, | ||
| session, | ||
| vite: { | ||
| plugins: [netlifyVitePlugin()], |
There was a problem hiding this comment.
Shouldn't we add this plugin only when running the dev command? That's what I understood from the PR description
There was a problem hiding this comment.
It looks like the plugin only implements the configureServer hook, so it won't affect builds: https://github.com/netlify/primitives/blob/main/packages/vite-plugin/src/main.ts
There was a problem hiding this comment.
I'm happy to make this more explicit on the adapter side if needed. What's your recommendation?
There was a problem hiding this comment.
I think just a mention in the docs of the plugin is more than enough :)
There was a problem hiding this comment.
I suppose this file and netlify/functions/func.mjs are part of the Netlify Vite plugin; however, the plugin's documentation doesn't mention these files.
I would appreciate if you could update the PR description, and guide us reviewers to understand what these files are for, and what we should expect.
Additionally, is there a link we can use to redirect our users to instructions on how to use these files?
There was a problem hiding this comment.
Those are just regular Netlify functions and edge functions, rather than anything related to the Vite plugin specifically. There's some info here: https://docs.astro.build/en/guides/deploy/netlify/#using-netlify-functions
There was a problem hiding this comment.
What should we expect from these functions though?
There was a problem hiding this comment.
I think just that they work as expected on a Netlify site (i.e. they run when they match a route)
@ascorbic Mind if we do this as a follow-up? I'd love to get the skeleton landed first. |
e192940 to
2825dc3
Compare
2825dc3 to
dd479d7
Compare
|
yay |
|
It looks like this is ready! Can you do a changeset? We should be able to get this in 5.11, and it would be great to be able to highlight this in the blog. The changeset should be written for the audience of end users, so rather than explaining the technical implementation in any detail (beyond saying that it now uses the Netlify Vite plugin), focus on what this means for the user. Are there any changes needed for docs? Does it change any of the instructions in the deployment guide or adapter docs? |
| image: { | ||
| service: { | ||
| entrypoint: enableImageCDN ? '@astrojs/netlify/image-service.js' : undefined, | ||
| entrypoint: integrationConfig?.imageCDN ? '@astrojs/netlify/image-service.js' : undefined, |
There was a problem hiding this comment.
This should default to true, so something like this (with a comment explaining why):
| entrypoint: integrationConfig?.imageCDN ? '@astrojs/netlify/image-service.js' : undefined, | |
| entrypoint: integrationConfig?.imageCDN === false ? undefined : '@astrojs/netlify/image-service.js', |
d584b7c to
364ac21
Compare
85679b9 to
2f0cfd8
Compare
2f0cfd8 to
b835391
Compare
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
* feat: load Netlify Vite plugin * chore: update `@netlify/vite-plugin` * update plugin and add tests * Update pnpm-lock.yaml * remove unused code * Deps * update plugin * remove unused file * Apply suggestions from code review Co-authored-by: Matt Kane <m@mk.gg> * Upgrade vite plugin * satisfy linter * Upgrade vite plugin * refactor: use Netlify primitives * make imageCDN an opt out, not an opt in * remove outside netlify test, for now we are never outside * update pnpm-lock * invalidate the astro session when restarting dev server * Update to latest vite plugin, functions and blobs * Add changeset for @astrojs/netlify on @netlify/vite-plugin * apply Sarah's changeset improvements Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --------- Co-authored-by: Matt Kane <m@mk.gg> Co-authored-by: chee <chee.rabbits@netlify.com> Co-authored-by: chee <chee@rabbits.computer> Co-authored-by: chee <yay@chee.party> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Changes
Loads the new (and experimental) Netlify Vite plugin, which means a few things:
Netlifyglobal, as well as the globals needed to use Netlify Blobs and the upcoming Netlify Cache API straight fromastro dev, without requiring the Netlify CLIastro devwill make the plugin automatically add the.netlifydirectory to the.gitignorefile, like the Netlify CLI doesI'm keeping it as draft for now because I still need to add some tests and update docs (see below). And above all, I'd love to hear your feedback, since this is a net new flow we're introducing.
Testing
I'd like to add some tests, but from a quick look it seems that the existing tests only assert the build output. Do we have a way to test the development flow?
Docs
I think we should update docs for this, both on the Astro side and on the Netlify side, explaining what will now become available during the local development process.
/cc @withastro/maintainers-docs for feedback!