Skip to content

feat: add vercel-static and netlify-static presets#1073

Merged
pi0 merged 13 commits into
mainfrom
feat/vercel-static
Apr 15, 2023
Merged

feat: add vercel-static and netlify-static presets#1073
pi0 merged 13 commits into
mainfrom
feat/vercel-static

Conversation

@danielroe

@danielroe danielroe commented Mar 21, 2023

Copy link
Copy Markdown
Member

🔗 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.

@danielroe danielroe added the enhancement New feature or request label Mar 21, 2023
@danielroe danielroe requested a review from pi0 March 21, 2023 15:35
@danielroe danielroe self-assigned this Mar 21, 2023
@codecov

codecov Bot commented Mar 21, 2023

Copy link
Copy Markdown

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
Copy Markdown

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

@danielroe

Copy link
Copy Markdown
Member Author

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

Comment thread src/utils/index.ts Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
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.

@pi0 pi0 Mar 24, 2023

Copy link
Copy Markdown
Member

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)

Comment thread src/presets/vercel.ts Outdated

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

Copy link
Copy Markdown
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

pi0 commented Mar 22, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

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

@pi0

pi0 commented Mar 22, 2023

Copy link
Copy Markdown
Member

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
@danielroe danielroe marked this pull request as ready for review April 13, 2023 08:53
Comment thread src/options.ts
presetOverride ||
(layers.find((l) => l.config.preset)?.config.preset as string) ||
defaultPreset;
(detectTarget({ static: !options.build }) ?? "node-server");

Copy link
Copy Markdown
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...

@danielroe danielroe Apr 13, 2023

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

Comment thread src/presets/vercel.ts Outdated

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

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

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