Skip to content

Commit

Permalink
only on dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Aug 27, 2023
1 parent 8aeeab1 commit 2a664d8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export function assetPlugin(config: ResolvedConfig): Plugin {

id = id.replace(urlRE, '$1').replace(unnededFinalQueryCharRE, '')
const url = await fileToUrl(id, config, this)
return `export default ${JSON.stringify(`${url}?t=${Date.now()}`)}`
return `export default ${JSON.stringify(
config.command === 'serve' ? `${url}?t=${Date.now()}` : url,
)}`
},

renderChunk(code, chunk, opts) {
Expand Down
14 changes: 8 additions & 6 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ describe('svg fragments', () => {

test('from js import', async () => {
const img = await page.$('.svg-frag-import')
expect(await img.getAttribute('src')).toMatch(/svg#icon-heart-view$/)
expect(await img.getAttribute('src')).toMatch(
isBuild ? /svg#icon-heart-view$/ : /svg\?t=\d+#icon-heart-view$/,
)
})
})

Expand Down Expand Up @@ -288,11 +290,11 @@ test('?url import', async () => {
test('?url import on css', async () => {
const src = readFile('css/icons.css')
const txt = await page.textContent('.url-css')
expect(txt).toEqual(
isBuild
? `data:text/css;base64,${Buffer.from(src).toString('base64')}`
: '/foo/css/icons.css',
)
isBuild
? expect(txt).toEqual(
`data:text/css;base64,${Buffer.from(src).toString('base64')}`,
)
: expect(txt).toMatch(/^\/foo\/css\/icons.css\?t=\d+$/)
})

describe('unicode url', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ describe('svg fragments', () => {

test('from js import', async () => {
const img = await page.$('.svg-frag-import')
expect(await img.getAttribute('src')).toMatch(/svg#icon-heart-view$/)
expect(await img.getAttribute('src')).toMatch(
isBuild ? /svg#icon-heart-view$/ : /svg\?t=\d+#icon-heart-view$/,
)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ describe('svg fragments', () => {

test('from js import', async () => {
const img = await page.$('.svg-frag-import')
expect(await img.getAttribute('src')).toMatch(/svg#icon-heart-view$/)
expect(await img.getAttribute('src')).toMatch(
isBuild ? /svg#icon-heart-view$/ : /svg\?t=\d+#icon-heart-view$/,
)
})
})

Expand Down
4 changes: 3 additions & 1 deletion playground/assets/__tests__/url-base/url-base-assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ describe('svg fragments', () => {

test('from js import', async () => {
const img = await page.$('.svg-frag-import')
expect(await img.getAttribute('src')).toMatch(/svg#icon-heart-view$/)
expect(await img.getAttribute('src')).toMatch(
isBuild ? /svg#icon-heart-view$/ : /svg\?t=\d+#icon-heart-view$/,
)
})
})

Expand Down

0 comments on commit 2a664d8

Please sign in to comment.