File tree Expand file tree Collapse file tree 7 files changed +69
-0
lines changed
Expand file tree Collapse file tree 7 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ import { expect , test } from 'vitest'
2+ import { page } from '~utils'
3+
4+ test ( 'absolute imports keep base prefix' , async ( ) => {
5+ await expect . poll ( ( ) => page . textContent ( '.message' ) ) . toBe ( 'absolute import' )
6+ } )
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < title > Base Conflict</ title >
6+ </ head >
7+ < body >
8+ < div id ="app " class ="message "> </ div >
9+ < script type ="module " src ="/src/main.ts "> </ script >
10+ </ body >
11+ </ html >
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @vitejs/test-base-conflict" ,
3+ "private" : true ,
4+ "version" : " 0.0.0" ,
5+ "type" : " module" ,
6+ "scripts" : {
7+ "dev" : " vite" ,
8+ "build" : " vite build" ,
9+ "debug" : " node --inspect-brk ../../packages/vite/bin/vite" ,
10+ "preview" : " vite preview"
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ export default 'absolute import'
Original file line number Diff line number Diff line change 1+ import message from 'absolute-importer'
2+
3+ document . querySelector ( '.message' ) ! . textContent = message
Original file line number Diff line number Diff line change 1+ declare module 'absolute-importer' {
2+ const msg : string
3+ export default msg
4+ }
Original file line number Diff line number Diff line change 1+ import { defineConfig , normalizePath } from 'vite'
2+
3+ const rootPath = normalizePath ( import . meta. dirname )
4+ const absoluteRoot = rootPath . startsWith ( '/' ) ? rootPath : `/${ rootPath } `
5+ const [ firstSegment ] = absoluteRoot . split ( '/' ) . filter ( Boolean )
6+ const base = firstSegment ? `/${ firstSegment } /` : '/'
7+
8+ const VIRTUAL_MODULE_ID = 'absolute-importer'
9+ const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID
10+
11+ const absoluteDepPath = `${ rootPath } /src/importee.ts`
12+ export default defineConfig ( {
13+ base,
14+ plugins : [
15+ {
16+ name : 'absolute-path-import' ,
17+ resolveId ( id ) {
18+ if ( id === VIRTUAL_MODULE_ID ) {
19+ return RESOLVED_VIRTUAL_MODULE_ID
20+ }
21+ } ,
22+ load ( id ) {
23+ if ( id === RESOLVED_VIRTUAL_MODULE_ID ) {
24+ return (
25+ `import dep from ${ JSON . stringify ( absoluteDepPath ) } \n` +
26+ `export default dep`
27+ )
28+ }
29+ } ,
30+ } ,
31+ ] ,
32+ } )
You can’t perform that action at this time.
0 commit comments