Skip to content

Commit 98782e7

Browse files
authored
feat: skip normal css files without scoped flag in stylePostLoader (#2053)
1 parent 8357e07 commit 98782e7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/stylePostLoader.ts

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ const { compileStyle } = compiler
99
// for any <style scoped> selection requests initiated from within vue files.
1010
const StylePostLoader: LoaderDefinitionFunction = function (source, inMap) {
1111
const query = qs.parse(this.resourceQuery.slice(1))
12+
13+
// skip normal CSS files without scoped flag
14+
if (
15+
!('vue' in query) ||
16+
query.type !== 'style' ||
17+
!query.id ||
18+
!query.scoped
19+
) {
20+
this.callback(null, source, inMap)
21+
return
22+
}
23+
1224
const { code, map, errors } = compileStyle({
1325
source: source as string,
1426
filename: this.resourcePath,

test/core.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test('style import', async () => {
7575
})
7676

7777
const styles = window.document.querySelectorAll('style')
78-
expect(styles[0].textContent).toContain('h1 { color: red;\n}')
78+
expect(styles[0].textContent).toContain('h1 { color: red; }')
7979

8080
// import with scoped
8181
const id = 'data-v-' + genId('style-import.vue')
@@ -89,7 +89,7 @@ test('style import for a same file twice', async () => {
8989

9090
const styles = window.document.querySelectorAll('style')
9191
expect(styles.length).toBe(3)
92-
expect(styles[0].textContent).toContain('h1 { color: red;\n}')
92+
expect(styles[0].textContent).toContain('h1 { color: red; }')
9393

9494
// import with scoped
9595
const id = 'data-v-' + genId('style-import-twice-sub.vue')

test/template.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ test('transform relative URLs and respects resolve alias', async () => {
5656
const style = normalizeNewline(
5757
window.document.querySelector('style')!.textContent!
5858
)
59-
expect(style).toContain('html { background-image: url(logo.cab72b.png);\n}')
60-
expect(style).toContain('body { background-image: url(logo.cab72b.png);\n}')
59+
expect(style).toContain('html { background-image: url(logo.cab72b.png); }')
60+
expect(style).toContain('body { background-image: url(logo.cab72b.png); }')
6161
})
6262

6363
test('customizing template loaders', async () => {

0 commit comments

Comments
 (0)