| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,6 @@ | |||
| 1 | 1 | import vue from '@vitejs/plugin-vue'; | |
| 2 | 2 | import vueJsx from '@vitejs/plugin-vue-jsx'; | |
| 3 | 3 | import path from 'path'; | |
| 4 | - import alias from '@rollup/plugin-alias'; | ||
| 5 | - import { fileURLToPath } from 'node:url'; | ||
| 6 | - import { dirname, resolve } from 'node:path'; | ||
| 7 | 4 | import { mergeConfig, type UserConfig } from 'vite'; | |
| 8 | 5 | import { baseConfig } from './base.js'; | |
| 9 | 6 | import { parse as babelParse } from '@babel/parser'; | |
@@ -13,29 +10,19 @@ import * as t from '@babel/types'; | |||
| 13 | 10 | import { getCliFlags } from '../helpers/cli-flags.js'; | |
| 14 | 11 | import { getTypeCheckPlugins, type TypeCheckControlOptions } from '../helpers/typescript-check.js'; | |
| 15 | 12 | ||
| 16 | - const __filename = fileURLToPath(import.meta.url); | ||
| 17 | - const __dirname = dirname(__filename); | ||
| 18 | - | ||
| 19 | 13 | export const vueConfig = ({ mode }, options: TypeCheckControlOptions = {}): UserConfig => { | |
| 20 | 14 | const targetMode = mode === 'development' ? 'development' : 'production'; | |
| 21 | 15 | const cliFlags = getCliFlags(); | |
| 22 | 16 | const isDevMode = targetMode === 'development'; | |
| 23 | 17 | const hmrActive = isDevMode && !!cliFlags.hmr; | |
| 24 | 18 | ||
| 25 | 19 | 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 | + }, | ||
| 26 | 24 | plugins: [ | |
| 27 | 25 | ...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 | - }, | ||
| 39 | 26 | // Enable Vue Single File Component support | |
| 40 | 27 | vue({ | |
| 41 | 28 | // NativeScript projects often use <script setup lang="ts"> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments