diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index 18074fe..bc4b08e 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -36,6 +36,10 @@ describe('Vite SVG Loader', () => { expect($svg[0].width.baseVal.value).to.equal(400) }) }) + it('keeps style tag in components', () => { + cy.get('#style-tag svg style') + .should('exist') + }) it('supports ?url param', () => { cy.get('#url').contains(/^\/assets\/test\..+\.svg/) diff --git a/examples/vue/src/App.vue b/examples/vue/src/App.vue index 99e7acd..4ff1966 100644 --- a/examples/vue/src/App.vue +++ b/examples/vue/src/App.vue @@ -4,6 +4,8 @@ import { defineAsyncComponent } from 'vue' import HelloWorld from './components/HelloWorld.vue' import Test from './assets/test.svg' import TestSkipSvgo from './assets/test.svg?skipsvgo' +//skipsvgo because svgo with some params will inline styles +import StyleTagTest from './assets/style.svg?skipsvgo' import testUrl from './assets/test.svg?url' import testRaw from './assets/test.svg?raw' @@ -28,6 +30,10 @@ const Async = defineAsyncComponent(() => import(`./assets/${name}.svg`)) +
+ +
+
{{ testUrl }}
diff --git a/examples/vue/src/assets/style.svg b/examples/vue/src/assets/style.svg new file mode 100644 index 0000000..9a39e9b --- /dev/null +++ b/examples/vue/src/assets/style.svg @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js index 87cc6c9..3f1fd34 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,9 @@ module.exports = function svgLoader (options = {}) { }).data } + // To prevent compileTemplate from removing the style tag + svg = svg.replace(/