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(vite,webpack): tree-shakable import.meta.* build flags #22428

Merged
merged 15 commits into from Aug 7, 2023

Conversation

varugasu
Copy link
Contributor

@varugasu varugasu commented Aug 1, 2023

πŸ”— Linked issue

Resolves #21862

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 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

Introduce:

  • import.meta.browser and replace process.browser
  • import.meta.client and replace process.client
  • import.meta.server and replace process.server
  • import.meta.dev and replace process.dev
  • import.meta.test and replace process.test

Remove unused flags:

  • mode
  • static

Define NuxtStaticBuildFlags:

  • browser
  • server
  • client
  • dev
  • test

Note that this also bumps the webpack server target to es2020 to be in line with vite's default target, and also to support import.meta.url on the server.

πŸ“ Checklist

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

danielroe and others added 3 commits August 1, 2023 12:17
Co-authored-by: Lucas Vargas <vargasmesh@users.noreply.github.com>
Co-authored-by: Lucas Vargas <vargasmesh@users.noreply.github.com>
@stackblitz
Copy link

stackblitz bot commented Aug 1, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@nuxt-studio
Copy link

nuxt-studio bot commented Aug 1, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio β†—οΈŽ View Live Preview 554c407

@varugasu varugasu changed the title feat(vite,webpack): treeshake import.meta.{client,server} feat(vite,webpack): introduce treeshakable import.meta build flags Aug 1, 2023
@varugasu varugasu changed the title feat(vite,webpack): introduce treeshakable import.meta build flags feat(vite,webpack): introduce treeshakable import.meta build flags Aug 1, 2023
@danielroe danielroe added this to the 3.7 milestone Aug 1, 2023
@@ -15,6 +15,7 @@
// Workaround for stub mode
// https://github.com/nuxt/framework/pull/3983
process.server = true
import.meta.server = true

Check notice

Code scanning / CodeQL

Syntax error Note

Error: Unexpected token
.then(r => r.default(process.server ? url : window.location.href)))
const url = import.meta.server ? nuxtApp.ssrContext.url : window.location.pathname
const SingleRenderer = import.meta.test && import.meta.dev && import.meta.server && url.startsWith('/__nuxt_component_test__/') && /* #__PURE__ */ defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
.then(r => r.default(import.meta.server ? url : window.location.href)))

Check warning

Code scanning / CodeQL

Client-side cross-site scripting (experimental) Medium Experimental

(Experimental) This may be a cross-site scripting vulnerability due to
a user-provided value
. Identified using machine learning.
@danielroe danielroe changed the title feat(vite,webpack): introduce treeshakable import.meta build flags feat(vite,webpack): tree-shakable import.meta.* build flags Aug 7, 2023
@danielroe danielroe merged commit ffd0223 into main Aug 7, 2023
27 checks passed
@danielroe danielroe deleted the feat/treeshake-env branch August 7, 2023 22:03
@github-actions github-actions bot mentioned this pull request Aug 7, 2023
This was referenced Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce treeshakableimport.meta build flags
2 participants