Skip to content

Commit

Permalink
feat(config): deprecate baseUrl in favor of site.url
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Nov 15, 2023
1 parent 3c75cf9 commit c8cb6d8
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 44 deletions.
38 changes: 35 additions & 3 deletions docs/content/2.guide/16.migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can continue defining `vueI18n` options in `i18n.config`. Refer to the [Vue

### Change the route key rules in `pages` option

The key of route set in the `pages` option has been changed to be file-based relative to the `pages/` directory in Nuxt, and **excluding the leading `/`**.
The key of route set in the `pages` option has been changed to be file-based relative to the `pages/` directory in Nuxt, and **excluding the leading `/`**.

The reason is that it is more intuitive to match Nuxt file-based routing.

Expand Down Expand Up @@ -83,6 +83,38 @@ Deprecated for the same reason as the `localeLocation()` Option API.
Use `localeHead()` instead for the Options API style.
### Deprecated `baseUrl` component option
Use `site.url` instead of `i18n.baseUrl`.
::alert{type="info"}
The `site` configuration option stems from [Nuxt SEO's `site-config` module](https://nuxtseo.com/site-config), which `nuxt-i18n` makes use of now.
::
Nuxt2:
```vue {}[nuxt.config.js]
<script>
import Vue from 'vue'
export default Vue.extend({
nuxtI18n: {
baseUrl: 'https://localhost:3000',
}
})
</script>
```
Nuxt3:
```vue {}[nuxt.config.js]
<script setup>
defineI18nRoute({
site: {
url: 'http://localhost:3000'
}
})
</script>
```
### Deprecated `nuxtI18n` component option
Replaced by the `defineI18nRoute()` compiler macro as it can be optimized with bundler.
Expand Down Expand Up @@ -122,7 +154,7 @@ Use the `customRoutes` option. because the option name `parsePages` is not intui
modules: [
'@nuxtjs/i18n'
],
i18n: {
// ...
- parsePages: false,
Expand All @@ -141,7 +173,7 @@ Use `dynamicRouteParams` option. Because Vuex is no longer required by the Nuxt
modules: [
'@nuxtjs/i18n'
],
i18n: {
// ...
- vuex: true,
Expand Down
23 changes: 16 additions & 7 deletions docs/content/2.guide/7.seo.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To leverage the SEO benefits, you must configure the `locales` option as an arra
```ts {}[nuxt.config.ts]
export default defineNuxtConfig({
// ...

i18n: {
locales: [
{
Expand All @@ -41,26 +41,35 @@ export default defineNuxtConfig({
}
]
},

// ...
})
```

You must also set the `baseUrl` option to your production domain in order to make alternate URLs fully-qualified:
You must also set the `site.url` option to your production domain in order to make alternate URLs fully-qualified:

```ts {}[nuxt.config.ts]
export default defineNuxtConfig({
// ...

i18n: {
baseUrl: 'https://my-nuxt-app.com'
site: {
url: 'https://my-nuxt-app.com'
},


// // this is deprecated
// i18n: {
// baseUrl: 'https://my-nuxt-app.com'
// },

// ...
})
```

(Note that `baseUrl` can also be set to a function. Check [`baseUrl` documentation](/options/routing#baseurl).)
::alert{type="info"}
The `site` configuration option stems from [Nuxt SEO's `site-config` module](https://nuxtseo.com/site-config).
::

:badge[Deprecated]{type="warning"} The site url can also be set using `i18n.baseUrl`. Note that `i18n.baseUrl` can also be set as a function as specified in [`i18n.baseUrl`'s documentation](/options/routing#baseurl).

## Setup

Expand Down
8 changes: 6 additions & 2 deletions docs/content/3.options/2.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Routing and Strategies options.

---

## `baseUrl`
## `baseUrl` :badge[Deprecated]{type="warning"}

::alert{type="warning"}
Use [Nuxt SEO's `site.url`](https://nuxtseo.com/site-config) instead of `i18n.baseUrl`.
::

- type: `string` or `function`
- default: `''`
Expand Down Expand Up @@ -132,7 +136,7 @@ Set to a path to which you want to redirect users accessing the root URL (`/`).
- type: `boolean`
- default: `false`

Whether to localize dynamic route parameters.
Whether to localize dynamic route parameters.

If `true`, you can set the dynamic route parameter to `nuxtI18n` field of `definePageMeta` for each locale:

Expand Down
18 changes: 11 additions & 7 deletions docs/content/3.options/9.runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Some options can be set via the `runtimeConfig`, setting options this way makes

## Usage

If you want to use environment variables to change [supported options](#supported-options), you will have to set these in `runtimeConfig.public.i18n`.
If you want to use environment variables to change [supported options](#supported-options), you will have to set these in `runtimeConfig.public.i18n`.

```ts {}[nuxt.config.ts]
export default defineNuxtConfig({
Expand All @@ -15,12 +15,12 @@ export default defineNuxtConfig({
],
i18n: {
// Leave options unset that you want to set using `runtimeConfig`
// baseUrl: 'https://example.com',
// defaultLocale: 'en',
},
runtimeConfig: {
public: {
i18n: {
baseUrl: 'https://example.com',
defaultLocale: 'en',
locales: {},
// other options ...
}
Expand All @@ -46,14 +46,18 @@ The module configuration takes precedence, options set through `runtimeConfig` w

These options can be set using `runtimeConfig`:

### `baseUrl`
* key: `NUXT_PUBLIC_I18N_BASE_URL`
### `baseUrl` :badge[Deprecated]{type="warning"}

::alert{type="warning"}
Use [Nuxt SEO's `site.url`](https://nuxtseo.com/site-config) instead of `i18n.baseUrl`.
::

This runtime config option is the same as the [`baseUrl`](./routing#baseUrl) module option.
* key: `NUXT_PUBLIC_I18N_BASE_URL`

This runtime config option is the same as the [`baseUrl`](./routing#baseUrl) module option.

::alert{type=warning}
Note that the `baseUrl` module option allows you to set the function, but the runtime config does not due to limitations.
Nuxt's runtime config does not allow values to be specified as functions, so you must use the `baseUrl` module option if you need to set the value using a function.
::

### `locales`
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
"knitwork": "^1.0.0",
"magic-string": "^0.30.4",
"mlly": "^1.4.2",
"nuxt-site-config": "^1.4.0",
"nuxt-site-config-kit": "^1.4.0",
"pathe": "^1.1.1",
"ufo": "^1.3.1",
"unplugin": "^1.5.0",
Expand Down
4 changes: 3 additions & 1 deletion playground/layer-module/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineNuxtConfig({
i18n: {
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand All @@ -30,5 +29,8 @@ export default defineNuxtConfig({
name: 'Nederlands'
}
]
},
site: {
url: 'http://localhost:3000'
}
})
4 changes: 3 additions & 1 deletion playground/layers/i18n-layer/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineNuxtConfig({
i18n: {
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
customRoutes: 'config',
pages: {
history: {
Expand Down Expand Up @@ -58,5 +57,8 @@ export default defineNuxtConfig({
// name: 'Français'
// }
]
},
site: {
url: 'http://localhost:3000'
}
})
5 changes: 3 additions & 2 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default defineNuxtConfig({
},
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down Expand Up @@ -117,7 +116,6 @@ export default defineNuxtConfig({
},
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down Expand Up @@ -179,5 +177,8 @@ export default defineNuxtConfig({
// // redirectOn: 'root'
// },
vueI18n: './vue-i18n.options.ts'
},
site: {
url: 'http://localhost:3000'
}
})
5 changes: 3 additions & 2 deletions playground/pages/blog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ defineI18nRoute({
}
})
const { t, locales, baseUrl } = useI18n({
const { t, locales } = useI18n({
useScope: 'local'
})
console.log('locales', locales, baseUrl)
const { url } = useSiteConfig()
console.log('locales', locales, url)
</script>

<template>
Expand Down
45 changes: 45 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion specs/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineNuxtConfig({

i18n: {
lazy: false,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand All @@ -22,5 +21,8 @@ export default defineNuxtConfig({
defaultLocale: 'en',
detectBrowserLanguage: false,
vueI18n: './config/i18n.config.ts'
},
site: {
url: 'http://localhost:3000'
}
})
4 changes: 3 additions & 1 deletion specs/fixtures/different_domains/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineNuxtConfig({

i18n: {
lazy: false,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand All @@ -23,5 +22,8 @@ export default defineNuxtConfig({
],
defaultLocale: 'ja',
detectBrowserLanguage: false
},
site: {
url: 'http://localhost:3000'
}
})
4 changes: 3 additions & 1 deletion specs/fixtures/issues/2247/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
baseUrl: 'https://abwaab.com',
locales: [
{
code: 'en',
Expand All @@ -27,5 +26,8 @@ export default defineNuxtConfig({
defaultLocale: 'ar',
lazy: true,
langDir: 'i18n/'
},
site: {
url: 'https://abwaab.com'
}
})

0 comments on commit c8cb6d8

Please sign in to comment.