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: add vercel-static and netlify-static presets #1073

Merged
merged 13 commits into from
Apr 15, 2023
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Mar 21, 2023

πŸ”— Linked issue

resolves #818
also nuxt/image#638, nuxt/image#617, nuxt/image#757

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This adds new vercel-static and netlify-static presets that will use platform features to handle redirects, headers, etc. For Vercel, this will also include Vercel Images config and solve nuxt/image#638.

It is not fully auto-detectable - frameworks that use it will need to pass build: false or otherwise configure this (which they can easily do if user is running some kind of generate command). But with that, we can then automatically enable provider-specific configuration for zero-config 'static+' deploys.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #1073 (c361b2b) into main (a45623d) will decrease coverage by 0.19%.
The diff coverage is 52.50%.

@@            Coverage Diff             @@
##             main    #1073      +/-   ##
==========================================
- Coverage   67.92%   67.73%   -0.19%     
==========================================
  Files          65       65              
  Lines        6406     6468      +62     
  Branches      713      717       +4     
==========================================
+ Hits         4351     4381      +30     
- Misses       2041     2072      +31     
- Partials       14       15       +1     
Impacted Files Coverage Ξ”
src/utils/index.ts 52.38% <36.36%> (-1.68%) ⬇️
src/presets/netlify.ts 56.98% <48.57%> (-2.64%) ⬇️
src/options.ts 87.70% <50.00%> (-0.04%) ⬇️
src/presets/vercel.ts 76.61% <55.71%> (-1.12%) ⬇️
src/build.ts 42.27% <100.00%> (+0.13%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@yunyuyuan
Copy link

Does vercel-static support Vercel serverless functions?From my tests, it seems that currently vercel or vercel-edge only support nuxt build and do not work with nuxt generate, when calling the /server/api/xxx, it returns a 405 error

Copy link
Member Author

No, this PR is purely static and does not render any serverless functions, just static assets, redirects, and headers.

export function detectTarget() {
return autodetectableProviders[provider];
}

// TODO: update when https://github.com/unjs/nitro/pull/1072 merges
export function detectStaticTarget() {
Copy link
Member

Choose a reason for hiding this comment

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

PR mergeed, also refactor, we might support { static }? for detectTarget itself to pas conditions like this without introducing new one

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered that but we need the resolved options first, and detectTarget is called beforehand.

Copy link
Member

@pi0 pi0 Mar 24, 2023

Choose a reason for hiding this comment

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

I mean not all options but detect conditions which for now is only static (practically merging two utils into one)

@@ -126,12 +126,33 @@ export const vercelEdge = defineNitroPreset({
},
});

export const vercelStatic = defineNitroPreset({
extends: "node",
entry: "#internal/nitro/entries/nitro-prerenderer",
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking more how we should approach this. Basing presets on prerenderer is an additional step and needs to be handled by nuxt. Whereas we could simply stop building server with static true.

@pi0
Copy link
Member

pi0 commented Mar 22, 2023

Thanks for the work on this PR @danielroe ❀️ More I'm thinking it would be nice if we (in an initial PR) introduce static preset + static flag that basically stops building server when is set. We can then extend vercel-static from it. Wdyt?

@danielroe
Copy link
Member Author

Seems good to me! Shall I refactor this PR to include that as well, or would you value a separate PR?

@pi0
Copy link
Member

pi0 commented Mar 22, 2023

A seperate PR would be nicer if you don't mind ❀️

@danielroe danielroe changed the title feat: add vercel-static preset feat: add vercel-static and netlify-static presets Apr 12, 2023
@@ -149,7 +148,7 @@ export async function loadOptions(
options.preset =
presetOverride ||
(layers.find((l) => l.config.preset)?.config.preset as string) ||
defaultPreset;
(detectTarget({ static: !options.build }) ?? "node-server");
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking since we didn't release nitropack yet, would it made sense that we introduced static: boolean flag instead of top level build flag? It is mainly for sake of static support we introduced flag...

Copy link
Member Author

@danielroe danielroe Apr 13, 2023

Choose a reason for hiding this comment

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

yes, that works πŸ‘ only downside is that it's less accurate - build: false is precisely what the flag does. The rest is enabled only by static presets.

Copy link
Member Author

Choose a reason for hiding this comment

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

you still prefer top-level static? very happy to change it if, on reflection, you feel that's the best.

src/presets/vercel.ts Outdated Show resolved Hide resolved
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

LGTM. Let's do static option refactor in another change

@pi0 pi0 merged commit fac5436 into main Apr 15, 2023
@pi0 pi0 deleted the feat/vercel-static branch April 15, 2023 13:42
@pi0 pi0 mentioned this pull request Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vercel-static
3 participants