fix(compiler-sfc): transformAssetUrls.base should not affect known module requests

fix https://github.com/vitejs/vite/issues/1343
This commit is contained in:
Evan You
2021-01-04 15:09:36 -05:00
parent c92990eff0
commit 2ea9867398
3 changed files with 22 additions and 23 deletions

View File

@@ -59,13 +59,15 @@ describe('compiler sfc: transform asset url', () => {
test('with explicit base', () => {
const { code } = compileWithAssetUrls(
`<img src="./bar.png"></img>` + // -> /foo/bar.png
`<img src="~bar.png"></img>` + // -> /foo/bar.png
`<img src="bar.png"></img>` + // -> bar.png (untouched)
`<img src="@theme/bar.png"></img>`, // -> @theme/bar.png (untouched)
`<img src="~bar.png"></img>` + // -> still converts to import
`<img src="@theme/bar.png"></img>`, // -> still converts to import
{
base: '/foo'
}
)
expect(code).toMatch(`import _imports_0 from 'bar.png'`)
expect(code).toMatch(`import _imports_1 from '@theme/bar.png'`)
expect(code).toMatchSnapshot()
})