Skip to content

Commit

Permalink
support v12: revert rollup-plugin, vite-plugin and loader
Browse files Browse the repository at this point in the history
  • Loading branch information
babu-ch committed Feb 21, 2025
1 parent 6ba93af commit df0d118
Show file tree
Hide file tree
Showing 45 changed files with 609 additions and 16 deletions.
25 changes: 25 additions & 0 deletions packages/rollup-plugin-vue-i18n/e2e/example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ describe('composition', () => {
})
})

describe('legacy', () => {
beforeAll(async () => {
await page.goto(`http://localhost:8080/legacy/`)
})

test('initial rendering', async () => {
await expect(page).toMatch('言語')
await expect(page).toMatch('こんにちは、世界!')
await expect(page).toMatch('バナナが欲しい?')
})

test('change select', async () => {
await page.select('#fruits select', '2')
await expect(page).toMatch('バナナ 2 個')
})

test('change locale', async () => {
await page.select('#app select', 'en')
await expect(page).toMatch('Language')
await expect(page).toMatch('hello, world!')
await expect(page).toMatch('Do you want banana?')
await expect(page).toMatch('2 bananas')
})
})

describe('global', () => {
beforeAll(async () => {
await page.goto(`http://localhost:8080/global/`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ja from './locales/ja.json5'
import en from './locales/en.yaml'

const i18n = createI18n({
legacy: false,
locale: 'ja',
messages: {
en,
Expand Down
1 change: 1 addition & 0 deletions packages/rollup-plugin-vue-i18n/examples/global/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createI18n } from 'vue-i18n'
import App from './App.vue'

const i18n = createI18n({
legacy: false,
locale: 'ja',
messages: {}
})
Expand Down
35 changes: 35 additions & 0 deletions packages/rollup-plugin-vue-i18n/examples/legacy/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<form>
<label>{{ $t('language') }}</label>
<select v-model="$i18n.locale">
<option value="en">en</option>
<option value="ja">ja</option>
</select>
</form>
<p>{{ $t('hello') }}</p>
<Banana />
</template>

<script>
import Banana from './Banana.vue'
export default {
name: 'App',
components: {
Banana
}
}
</script>

<i18n>
{
"en": {
"language": "Language",
"hello": "hello, world!"
},
"ja": {
"language": "言語",
"hello": "こんにちは、世界!"
}
}
</i18n>
19 changes: 19 additions & 0 deletions packages/rollup-plugin-vue-i18n/examples/legacy/Banana.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<form id="fruits">
<label>{{ $t('select') }}</label>
<select v-model.number="select">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<p>{{ $tc('fruits.banana', select, { n: select }) }}</p>
</template>

<script>
export default {
name: 'Banana',
data: () => ({ select: 0 })
}
</script>
13 changes: 13 additions & 0 deletions packages/rollup-plugin-vue-i18n/examples/legacy/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>rollup-plugin-vue-i18n composable example</title>
</head>
<body>
<div id="app">
<App />
</div>
<script src="./index.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select: Do you want banana?
fruits:
banana: 'no bananas | {n} banana | {n} bananas'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"select": "バナナが欲しい?",
"fruits": {
"banana": "バナナがない | バナナ {n} 個"
}
}
20 changes: 20 additions & 0 deletions packages/rollup-plugin-vue-i18n/examples/legacy/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'

import ja from './locales/ja.json'
import en from './locales/en.yaml'

const i18n = createI18n({
legacy: true,
locale: 'ja',
messages: {
en,
ja
}
})

const app = createApp(App)

app.use(i18n)
app.mount('#app')
2 changes: 2 additions & 0 deletions packages/rollup-plugin-vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@
"build:example": "yarn build && npm-run-all --parallel \"build:example:*\"",
"build:example:composition": "rollup -c ./examples/rollup.config.js --environment BUILD:composition",
"build:example:global": "rollup -c ./examples/rollup.config.js --environment BUILD:global",
"build:example:legacy": "rollup -c ./examples/rollup.config.js --environment BUILD:legacy",
"clean": "npm-run-all \"clean:*\"",
"clean:example": "npm-run-all \"clean:example:*\"",
"clean:example:composition": "rm -rf ./examples/composition/index.js",
"clean:example:global": "rm -rf ./examples/global/index.js",
"clean:example:legacy": "rm -rf ./examples/legacy/index.js",
"clean:lib": "rm -rf ./lib",
"test": "yarn test:e2e",
"test:e2e": "yarn build:example && jest --runInBand --config ./jest.e2e.config.js",
Expand Down
20 changes: 17 additions & 3 deletions packages/vite-plugin-vue-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ $ yarn add -D @intlify/vite-plugin-vue-i18n

## ⚠️ Notice

If you do a production build with vite, Vue I18n will automatically bundle the runtime only module. If you need on-demand compilation with Message compiler, you need to set the `runtimeOnly` option to `false`.
When this plugin is installed, Vue I18n can only use the Composition API, and if you want to use the Legacy API, you need to set the `compositionOnly` option to `false`.

Also, if you do a production build with vite, Vue I18n will automatically bundle the runtime only module. If you need on-demand compilation with Message compiler, you need to set the `runtimeOnly` option to `false`.

## 🚀 Usage

Expand All @@ -62,6 +64,9 @@ export default defineConfig({
plugins: [
vue(), // you need to install `@vitejs/plugin-vue`
vueI18n({
// if you want to use Vue I18n Legacy API, you need to set `compositionOnly: false`
// compositionOnly: false,

// you need to set i18n resource including paths !
include: resolve(
dirname(fileURLToPath(import.meta.url)),
Expand Down Expand Up @@ -265,14 +270,23 @@ About details, See the below section

For more details, See [here](#-automatic-bundling)

### `compositionOnly`

- **Type:** `boolean`
- **Default:** `true`

Whether to make vue-i18n's API only composition API. **By default the legacy API is tree-shaken.**

For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)

### `fullInstall`

- **Type:** `boolean`
- **Default:** `true`

Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.

If `false` is specified, **build-in components and directive will not be installed in vue and will be tree-shaken.**
If `false` is specified, **buld-in components and directive will not be installed in vue and will be tree-shaken.**

For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)

Expand Down Expand Up @@ -399,7 +413,7 @@ About details, See the below section

Whether to use the import name of `petite-vue-i18n` with the same import name as vue-i18n (`import { xxx } from 'vue-i18n'`).

This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhancement.
This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhacement.

## 📜 Changelog

Expand Down
26 changes: 26 additions & 0 deletions packages/vite-plugin-vue-i18n/e2e/legacy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('legacy', () => {
beforeAll(async () => {
await page.goto(`http://localhost:8080/legacy/`)
})

test('initial rendering', async () => {
await expect(page).toMatch('言語')
await expect(page).toMatch('こんにちは、世界!')
await expect(page).toMatch('バナナが欲しい?')
await expect(page).toMatch('バナナ 0 個')
})

test('change locale', async () => {
await page.select('#app select', 'en')
await expect(page).toMatch('Language')
await expect(page).toMatch('hello, world!')
await expect(page).toMatch('no bananas')
})

test('change banana select', async () => {
await page.select('#fruits select', '3')
await expect(page).toMatch('3 bananas')
await page.select('#app select', 'ja')
await expect(page).toMatch('バナナ 3 個')
})
})
1 change: 1 addition & 0 deletions packages/vite-plugin-vue-i18n/examples/composition/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import App from './App.vue'
import messages from '@intlify/vite-plugin-vue-i18n/messages'

const i18n = createI18n({
legacy: false,
locale: 'ja',
messages
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default defineConfig({
plugins: [
vue(),
vueI18n({
include: path.resolve(__dirname, './locales/**')
include: path.resolve(__dirname, './locales/**'),
compositionOnly: true
})
]
})
1 change: 1 addition & 0 deletions packages/vite-plugin-vue-i18n/examples/global/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createI18n } from 'vue-i18n'
import App from './App.vue'

const i18n = createI18n({
legacy: false,
locale: 'ja'
})

Expand Down
7 changes: 6 additions & 1 deletion packages/vite-plugin-vue-i18n/examples/global/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ import vue from '@vitejs/plugin-vue'
import vueI18n from '../../src/index'

export default defineConfig({
plugins: [vue(), vueI18n({})]
plugins: [
vue(),
vueI18n({
compositionOnly: true
})
]
})
35 changes: 35 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<form>
<label>{{ $t('language') }}</label>
<select v-model="$i18n.locale">
<option value="en">en</option>
<option value="ja">ja</option>
</select>
</form>
<p>{{ $t('hello') }}</p>
<Banana />
</template>

<script>
import Banana from './Banana.vue'
export default {
name: 'App',
components: {
Banana
}
}
</script>

<i18n>
{
"en": {
"language": "Language",
"hello": "hello, world!"
},
"ja": {
"language": "言語",
"hello": "こんにちは、世界!"
}
}
</i18n>
19 changes: 19 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/Banana.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<form id="fruits">
<label>{{ $t('select') }}</label>
<select v-model.number="select">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<p>{{ $tc('fruits.banana', select, { n: select }) }}</p>
</template>

<script>
export default {
name: 'Banana',
data: () => ({ select: 0 })
}
</script>
11 changes: 11 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>vite-plugin-vue-i18n legacy example</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./main.ts"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/locales/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select: Do you want banana?
fruits:
banana: 'no bananas | {n} banana | {n} bananas'
6 changes: 6 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/locales/ja.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"select": "バナナが欲しい?",
"fruits": {
"banana": "バナナがない | バナナ {n} 個"
}
}
19 changes: 19 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'
import en from './locales/en.yaml'
import ja from './locales/ja.json'

const i18n = createI18n({
legacy: true,
locale: 'ja',
messages: {
en,
ja
}
})

const app = createApp(App)

app.use(i18n)
app.mount('#app')
14 changes: 14 additions & 0 deletions packages/vite-plugin-vue-i18n/examples/legacy/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueI18n from '../../src/index'

export default defineConfig({
plugins: [
vue(),
vueI18n({
include: path.resolve(__dirname, './locales/**'),
compositionOnly: false
})
]
})
Loading

0 comments on commit df0d118

Please sign in to comment.