Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (specifier !== undefined) {
// skip external / data uri
if (
(isExternalUrl(specifier) && !specifier.startsWith('file://')) ||
isDataUrl(specifier)
((isExternalUrl(specifier) && !specifier.startsWith('file://')) ||
isDataUrl(specifier)) &&
!matchAlias(specifier)
) {
return
}
Expand Down
6 changes: 6 additions & 0 deletions playground/alias/__tests__/alias.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ test('aliased module', async () => {
)
})

test('url conflict alias', async () => {
expect(await page.textContent('.url-conflict')).toMatch(
'[success] url conflict alias',
)
})

test('custom resolver', async () => {
expect(await page.textContent('.custom-resolver')).toMatch(
'[success] alias to custom-resolver path',
Expand Down
1 change: 1 addition & 0 deletions playground/alias/dir/url_conflict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = `[success] url conflict alias`
3 changes: 3 additions & 0 deletions playground/alias/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ <h1>Alias</h1>
<p class="regex"></p>
<p class="dep"></p>
<p class="from-script-src"></p>
<p class="url-conflict"></p>
<p class="aliased-module"></p>
<p class="custom-resolver"></p>

Expand All @@ -17,6 +18,7 @@ <h1>Alias</h1>
import { msg as regexMsg } from 'regex/test'
import { msg as depMsg } from 'dep'
import { msg as moduleMsg } from 'aliased-module/index.js'
import { msg as urlConflictMsg } from '//url_conflict.js'
import { msg as customResolverMsg } from 'custom-resolver'

function text(el, text) {
Expand All @@ -28,6 +30,7 @@ <h1>Alias</h1>
text('.regex', regexMsg + ' via regex')
text('.dep', depMsg)
text('.aliased-module', moduleMsg)
text('.url-conflict', urlConflictMsg)
text('.custom-resolver', customResolverMsg)

import { createApp } from 'vue'
Expand Down
2 changes: 2 additions & 0 deletions playground/alias/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default defineConfig({
replacement: `${path.resolve(__dirname, 'dir')}/$1`,
},
{ find: '/@', replacement: path.resolve(__dirname, 'dir') },
// aliasing a pattern that conflicts with url schemes
{ find: /^\/\//, replacement: path.join(__dirname, 'dir/') },
// aliasing an optimized dep
{ find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' },
// aliasing an optimized dep to absolute URL
Expand Down
Loading