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 Oct 9, 2023
1 parent b818011 commit 7931245
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 104 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,15 +15,15 @@ export default defineNuxtConfig({
],
i18n: {
// Leave options unset that you want to set using `runtimeConfig`
// baseUrl: 'https://example.com',
// defaultLocale: 'en',
// experimental: {
// jsTsFormatResource: true,
// },
},
runtimeConfig: {
public: {
i18n: {
baseUrl: 'https://example.com',
defaultLocale: 'en',
experimental: {
jsTsFormatResource: true,
},
Expand Down Expand Up @@ -52,14 +52,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.
::

### `experimental`
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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",
"pkg-types": "^1.0.3",
"ufo": "^1.3.1",
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 @@ -120,7 +119,6 @@ export default defineNuxtConfig({
},
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down Expand Up @@ -182,5 +180,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
Loading

0 comments on commit 7931245

Please sign in to comment.