Skip to content

Commit

Permalink
fix: handle url imports with semicolon (close vitejs#7717)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoattal committed Apr 13, 2022
1 parent cb5c3f9 commit 534e1b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/vite/src/node/__tests__/plugins/css.spec.ts
Expand Up @@ -122,6 +122,12 @@ describe('hoist @ rules', () => {
expect(result).toBe(`@import "bla";.foo{color:red;}`)
})

test('hoist @import url with semicolon', async () => {
const css = `.foo{color:red;}@import url("bla;bla");`
const result = await hoistAtRules(css)
expect(result).toBe(`@import url("bla;bla");.foo{color:red;}`)
})

test('hoist @import with semicolon in quotes', async () => {
const css = `.foo{color:red;}@import "bla;bar";`
const result = await hoistAtRules(css)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -1112,7 +1112,7 @@ export async function hoistAtRules(css: string) {
// CSS @import can only appear at top of the file. We need to hoist all @import
// to top when multiple files are concatenated.
// match until semicolon that's not in quotes
s.replace(/@import\s*(?:"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
s.replace(/@import\s*(?:url\()?(?:"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
s.appendLeft(0, match)
return ''
})
Expand Down

0 comments on commit 534e1b1

Please sign in to comment.