Skip to content

feat(vite,webpack): tree-shakable import.meta.* build flags#22428

Merged
danielroe merged 15 commits intomainfrom
feat/treeshake-env
Aug 7, 2023
Merged

feat(vite,webpack): tree-shakable import.meta.* build flags#22428
danielroe merged 15 commits intomainfrom
feat/treeshake-env

Conversation

@varugasu
Copy link
Copy Markdown
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>
@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@nuxt-studio
Copy link
Copy Markdown
Contributor

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

Check notice

Code scanning / CodeQL

Syntax error

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)

(Experimental) This may be a cross-site scripting vulnerability due to [a user-provided value](1). 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
@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

3 participants