From 9b6f1b9a3ef9f4b50c83c46b997df497a87b72e9 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Thu, 7 Mar 2024 20:27:37 +0100 Subject: [PATCH] refactor!: remove vite config builtin aliases --- src/client/config.ts | 22 +------------------- tests/client/config.spec.ts | 40 ------------------------------------- 2 files changed, 1 insertion(+), 61 deletions(-) diff --git a/src/client/config.ts b/src/client/config.ts index fbea3c5..b21a90d 100644 --- a/src/client/config.ts +++ b/src/client/config.ts @@ -8,30 +8,11 @@ */ import { join } from 'node:path' -import type { AliasOptions, ConfigEnv, Plugin, UserConfig } from 'vite' +import type { ConfigEnv, Plugin, UserConfig } from 'vite' import { addTrailingSlash } from '../utils.js' import type { PluginFullOptions } from './types.js' -/** - * Resolve the `config.resolve.alias` value - * - * Basically we are merging the user defined alias with the - * default alias. - */ -export function resolveAlias(config: UserConfig): AliasOptions { - const defaultAlias = { '@/': `/resources/js/` } - - if (Array.isArray(config.resolve?.alias)) { - return [ - ...(config.resolve?.alias ?? []), - ...Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement })), - ] - } - - return { ...defaultAlias, ...config.resolve?.alias } -} - /** * Resolve the `config.base` value */ @@ -58,7 +39,6 @@ export function configHook( ): UserConfig { const config: UserConfig = { publicDir: userConfig.publicDir ?? false, - resolve: { alias: resolveAlias(userConfig) }, base: resolveBase(userConfig, options, command), build: { diff --git a/tests/client/config.spec.ts b/tests/client/config.spec.ts index 030a876..a95848c 100644 --- a/tests/client/config.spec.ts +++ b/tests/client/config.spec.ts @@ -37,46 +37,6 @@ test.group('Vite plugin', () => { await assert.fileContains('public/assets/foo.json', 'resources/js/app.ts') }) - test('user aliases are preserved', async ({ assert }) => { - const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'] })[1] as Plugin - - // @ts-ignore - const config = plugin!.config!( - { resolve: { alias: { '@test/': '/test/', '@foo': '/foo/' } } }, - { command: 'build' } - ) - - assert.deepEqual(config.resolve.alias, { - '@/': '/resources/js/', - '@test/': '/test/', - '@foo': '/foo/', - }) - }) - - test('flatten existing aliases', async ({ assert }) => { - const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'] })[1] as Plugin - - // @ts-ignore - const config = plugin!.config!( - { resolve: { alias: [{ find: '@test/', replacement: '/test/' }] } }, - { command: 'build' } - ) - - assert.deepEqual(config.resolve.alias, [ - { find: '@test/', replacement: '/test/' }, - { find: '@/', replacement: '/resources/js/' }, - ]) - }) - - test('user should be able to override the default alias', async ({ assert }) => { - const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'] })[1] as Plugin - - // @ts-ignore - const config = plugin!.config!({ resolve: { alias: { '@/': '/test/' } } }, { command: 'build' }) - - assert.deepEqual(config.resolve.alias, { '@/': '/test/' }) - }) - test('define the asset url', async ({ assert }) => { const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'],