forked from umijs/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundler-vite): support reference alias (umijs#311)
* feat(bundler-vite): resolving config overrides * feat(bundler-vite): Fix naming and block errors * feat(bundler-vite): fix alias * feat(bundler-vite): add alias.test.ts add cycle alias reference process * feat(bundler-vite): fix alias and alias.test * feat(bundler-vite): docfix
- Loading branch information
1 parent
9d3c912
commit e8e65fa
Showing
3 changed files
with
140 additions
and
12 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
packages/bundler-vite/src/config/transformer/alias.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import alias from './alias'; | ||
|
||
describe('alias config transformer', () => { | ||
test('no alias', () => { | ||
expect(alias({}, {})).toEqual({ | ||
resolve: { | ||
alias: [{ find: /^~/, replacement: '' }], | ||
}, | ||
}); | ||
}); | ||
|
||
test('normal alias replacement', () => { | ||
expect( | ||
alias( | ||
{ | ||
alias: { | ||
umi: '@@/exports', | ||
'@': '/umi-next/examples/umi', | ||
}, | ||
}, | ||
{}, | ||
), | ||
).toEqual({ | ||
resolve: { | ||
alias: [ | ||
{ find: /^~?umi(?=\/|$)/, replacement: '@@/exports' }, | ||
{ | ||
find: /^~?@(?=\/|$)/, | ||
replacement: '/umi-next/examples/umi', | ||
}, | ||
{ find: /^~/, replacement: '' }, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
//多层递归 alias | ||
test('Multi-level alias replacement', () => { | ||
expect( | ||
alias( | ||
{ | ||
alias: { | ||
umi: '@@/exports', | ||
'@@': '/umi-next/examples/umi', | ||
}, | ||
}, | ||
{}, | ||
), | ||
).toEqual({ | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: /^~?umi(?=\/|$)/, | ||
replacement: '/umi-next/examples/umi/exports', | ||
}, | ||
{ | ||
find: /^~?@@(?=\/|$)/, | ||
replacement: '/umi-next/examples/umi', | ||
}, | ||
{ find: /^~/, replacement: '' }, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
//循环 alias ,以最后一次设置为准 | ||
test('dead cycle alias replacement', () => { | ||
expect( | ||
alias( | ||
{ | ||
alias: { | ||
umi: '@@/exports', | ||
'@@/exports': 'umi', | ||
}, | ||
}, | ||
{}, | ||
), | ||
).toEqual({ | ||
resolve: { | ||
alias: [ | ||
{ find: /^~?umi(?=\/|$)/, replacement: 'umi' }, | ||
{ | ||
find: /^~?@@\/exports(?=\/|$)/, | ||
replacement: 'umi', | ||
}, | ||
{ find: /^~/, replacement: '' }, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters