Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

feat: improve base url options#2655

Merged
pi0 merged 36 commits intomainfrom
fix/cdn-refactor
Jan 18, 2022
Merged

feat: improve base url options#2655
pi0 merged 36 commits intomainfrom
fix/cdn-refactor

Conversation

@danielroe
Copy link
Copy Markdown
Member

🔗 Linked issue

resolves nuxt/nuxt#11406, resolves nuxt/nuxt#12612, resolves nuxt/nuxt#12675, resolves nuxt/nuxt#12652, resolves nuxt/nuxt#12922, resolves nuxt/nuxt#12892, resolves nuxt/nuxt#13098

Related: nuxt/bridge#223 (will fix in follow-up PR)

Previous PRs

closes #2249, closes #2262

❓ 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR refactors how we configure the base path of an application (previously router.base), the build assets path (previously build.publicPath) and any CDN URL.

export default defineNuxtConfig({
  build: {
    publicPath: '/_nuxt' // now app.buildAssetsPath
  },
  router: {
    base: '/' // now app.basePath
  },
  app: {
    base: '/',
    buildAssetsPath: '/_nuxt/',
    // optionally
    // cdnURL: 'https://mycdn.org/' 
  }
})

It also implements dynamic configuration for BASE_PATH and CDN_URL (which must end with /):

BASE_PATH=/foo/ CDN_URL=https://mycdn.org/ node .output/server/index.mjs

If there are static assets (such as images in the ~/public folder) which should be updated to the dynamically configured path, these should be indicated by using a 'magic' string:

<template>
  <img src="/__NUXT_BASE__/logo.svg" alt="My logo loaded from a dynamic base path.">
</template>

Note: With nuxt/nuxt#10197, this PR also adds dynamic router base + CDN support for Nuxt Bridge (with the exception of the static file 'dynamic' prefix with /__NUXT_BASE__/ which only applies to Nuxt 3).

📝 Checklist

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

@danielroe danielroe added bug Something isn't working enhancement New feature or request nitro vite webpack bridge schema labels Jan 10, 2022
@danielroe danielroe self-assigned this Jan 10, 2022
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 10, 2022

✔️ Deploy Preview for nuxt3-docs canceled.

🔨 Explore the source changes: 78ed9b0

🔍 Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61e5e0d408b7610007ba0a2a

@danielroe danielroe requested review from antfu and pi0 January 10, 2022 15:23
@pi0 pi0 changed the title refactor: combine existing cdn-focused PRs feat: improve cdn URL handling Jan 11, 2022
Comment thread packages/nitro/src/build.ts Outdated
Comment thread packages/nitro/src/runtime/app/render.ts Outdated
Comment thread packages/nitro/src/runtime/entries/cloudflare.ts Outdated
Comment thread packages/nitro/src/runtime/server/static.ts Outdated
Comment thread packages/nitro/src/server/dev.ts Outdated
Comment thread packages/vite/src/plugins/dynamic-base.ts
Comment thread packages/vite/src/plugins/dynamic-base.ts Outdated
Comment thread packages/vite/src/manifest.ts Outdated
Comment thread packages/schema/src/config/_app.ts Outdated
Comment thread packages/vite/src/plugins/dynamic-base.ts
Comment thread packages/bridge/src/vite/client.ts Outdated
Comment thread packages/bridge/src/vite/server.ts Outdated
Comment thread packages/nitro/src/rollup/config.ts Outdated
Comment thread packages/nitro/src/runtime/app/render.ts Outdated
Comment thread packages/nitro/src/runtime/app/render.ts Outdated
Comment thread packages/nitro/src/runtime/entries/cloudflare.ts Outdated
Comment thread packages/vite/src/plugins/dynamic-base.ts
Comment thread packages/vite/src/server.ts Outdated
Comment thread packages/nitro/src/runtime/app/config.ts Outdated
@pi0 pi0 changed the title feat: improve cdn URL handling feat: improve base url options Jan 18, 2022
@pi0 pi0 merged commit d07d572 into main Jan 18, 2022
@pi0 pi0 deleted the fix/cdn-refactor branch January 18, 2022 16:59
@huuhait
Copy link
Copy Markdown

huuhait commented Jan 19, 2022

nuxt/nuxt#13249

@misaon
Copy link
Copy Markdown
Contributor

misaon commented Jan 19, 2022

This PR is total BR for existing projects 😄

@danielroe
Copy link
Copy Markdown
Member Author

@misaon I'm not sure I understand what that means ... If you're experiencing an issue, would you create one and we'll do our best to address it.

@misaon
Copy link
Copy Markdown
Contributor

misaon commented Jan 19, 2022

@danielroe maybe...
i could find one mistake after all.
If I import an image (ViteJS style) in the <script setup> section, after building into the production environment, this path is prepended with 'NUXT_BASE'.

<template>
  <img :src="ImageLogo" />
</template>
<script lang="ts" setup>
import ImageLogo from 'assets/images/logo.svg'
</script>

Result image path (in prod): http://localhost:3000/__NUXT_BASE__/_nuxt/logo.736bc560.svg

@Harkonnen13
Copy link
Copy Markdown

Harkonnen13 commented Jan 20, 2022

@danielroe Ye, i have same issue with images as @misaon noticed
Production build
image
image
image
image

@Harkonnen13
Copy link
Copy Markdown

Dev build looks fine
image
image

@eMeRiKa13
Copy link
Copy Markdown

eMeRiKa13 commented Jan 20, 2022

Same problem for me, my production build doesn't display images from my assets folder anymore because I have /__NUXT_BASE__/_nuxt/image.png

@misaon
Copy link
Copy Markdown
Contributor

misaon commented Jan 20, 2022

@danielroe @pi0 Do you know about this issue?

@danielroe
Copy link
Copy Markdown
Member Author

Yes. Please follow nuxt/nuxt#13250 for progress.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

7 participants