Skip to content

Commit

Permalink
feat: optimize perf of stylePostLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjiang committed Oct 4, 2023
1 parent 2bc2858 commit 41121e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/stylePostLoader.ts
Expand Up @@ -11,7 +11,12 @@ 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.scoped) {
if (
!('vue' in query) ||
query.type !== 'style' ||
!query.id ||
!query.scoped
) {
this.callback(null, source, inMap)
return
}
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 41121e2

Please sign in to comment.