FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(vite): alias vue through resolve.alias so the Vue flavor builds u… · NativeScript/NativeScript@8dc3823 · GitHub

Repository navigation

Commit 8dc3823

Browse files
authored
fix(vite): alias vue through resolve.alias so the Vue flavor builds under rolldown (#11431)
[skip ci]
1 parent 3ed2ff7 commit 8dc3823

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
3+
// baseConfig resolves @nativescript/core from disk; only the Vue layer is under test
4+
vi.mock('./base.js', () => ({ baseConfig: () => ({}) }));
5+
6+
import { vueConfig } from './vue.js';
7+
8+
describe('vueConfig', () => {
9+
it('aliases vue to nativescript-vue through resolve.alias rather than a rollup alias plugin', () => {
10+
// Under rolldown, @rollup/plugin-alias resolved the bare replacement to
11+
// the package directory and every SFC's injected `from "vue"` failed.
12+
const config = vueConfig({ mode: 'production' });
13+
const aliases = config.resolve?.alias as Array<{ find: string | RegExp; replacement: string }>;
14+
expect(Array.isArray(aliases)).toBe(true);
15+
expect(aliases).toContainEqual({ find: 'vue', replacement: 'nativescript-vue' });
16+
const pluginNames = (config.plugins ?? []).flat().map((p: any) => p?.name);
17+
expect(pluginNames).not.toContain('alias');
18+
});
19+
});

‎packages/vite/configuration/vue.ts‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import vue from '@vitejs/plugin-vue';
22
import vueJsx from '@vitejs/plugin-vue-jsx';
33
import path from 'path';
4-
import alias from '@rollup/plugin-alias';
5-
import { fileURLToPath } from 'node:url';
6-
import { dirname, resolve } from 'node:path';
74
import { mergeConfig, type UserConfig } from 'vite';
85
import { baseConfig } from './base.js';
96
import { parse as babelParse } from '@babel/parser';
@@ -13,29 +10,19 @@ import * as t from '@babel/types';
1310
import { getCliFlags } from '../helpers/cli-flags.js';
1411
import { getTypeCheckPlugins, type TypeCheckControlOptions } from '../helpers/typescript-check.js';
1512

16-
const __filename = fileURLToPath(import.meta.url);
17-
const __dirname = dirname(__filename);
18-
1913
export const vueConfig = ({ mode }, options: TypeCheckControlOptions = {}): UserConfig => {
2014
const targetMode = mode === 'development' ? 'development' : 'production';
2115
const cliFlags = getCliFlags();
2216
const isDevMode = targetMode === 'development';
2317
const hmrActive = isDevMode && !!cliFlags.hmr;
2418

2519
return mergeConfig(baseConfig({ mode, flavor: 'vue' }), {
20+
resolve: {
21+
// @rollup/plugin-alias resolves a bare package to its directory under rolldown
22+
alias: [{ find: 'vue', replacement: 'nativescript-vue' }],
23+
},
2624
plugins: [
2725
...getTypeCheckPlugins('vue', options.typeCheck),
28-
{
29-
...alias({
30-
entries: {
31-
// Retain 'vue' alias to 'nativescript-vue' so any generic Vue imports resolve
32-
// to the NativeScript-Vue runtime.
33-
vue: 'nativescript-vue',
34-
'set-value': resolve(__dirname, '../shims/set-value.js'),
35-
},
36-
}),
37-
enforce: 'pre',
38-
},
3926
// Enable Vue Single File Component support
4027
vue({
4128
// NativeScript projects often use <script setup lang="ts">

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL