Skip to content

Commit

Permalink
feat: skip normal css files without scoped flag in stylePostLoader (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjiang committed Oct 7, 2023
1 parent 8357e07 commit 98782e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/stylePostLoader.ts
Expand Up @@ -9,6 +9,18 @@ const { compileStyle } = compiler
// for any <style scoped> selection requests initiated from within vue files.
const StylePostLoader: LoaderDefinitionFunction = function (source, inMap) {
const query = qs.parse(this.resourceQuery.slice(1))

// skip normal CSS files without scoped flag
if (
!('vue' in query) ||
query.type !== 'style' ||
!query.id ||
!query.scoped
) {
this.callback(null, source, inMap)
return
}

const { code, map, errors } = compileStyle({
source: source as string,
filename: this.resourcePath,
Expand Down
4 changes: 2 additions & 2 deletions test/core.spec.ts
Expand Up @@ -75,7 +75,7 @@ test('style import', async () => {
})

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

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

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

// import with scoped
const id = 'data-v-' + genId('style-import-twice-sub.vue')
Expand Down
4 changes: 2 additions & 2 deletions test/template.spec.ts
Expand Up @@ -56,8 +56,8 @@ test('transform relative URLs and respects resolve alias', async () => {
const style = normalizeNewline(
window.document.querySelector('style')!.textContent!
)
expect(style).toContain('html { background-image: url(logo.cab72b.png);\n}')
expect(style).toContain('body { background-image: url(logo.cab72b.png);\n}')
expect(style).toContain('html { background-image: url(logo.cab72b.png); }')
expect(style).toContain('body { background-image: url(logo.cab72b.png); }')
})

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

0 comments on commit 98782e7

Please sign in to comment.