Skip to content

Commit 336a1b2

Browse files
committed
fix: include .svg in issuer
1 parent c6d0f04 commit 336a1b2

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
test: /\.svg$/,
3232
// If you want to import svg in css files
3333
// You need to configure another rule to use file-loader for that
34-
issuer: /\.(vue|js|ts)$/,
34+
issuer: /\.(vue|js|ts|svg)$/,
3535
use: [
3636
// This loader compiles .svg file to .vue file
3737
// So we use `vue-loader` after it
@@ -78,7 +78,7 @@ In your `vue.config.js`:
7878
module.exports = {
7979
chainWebpack(config) {
8080
// Only convert .svg files that are imported by these files as Vue component
81-
const FILE_RE = /\.(vue|js|ts)$/
81+
const FILE_RE = /\.(vue|js|ts|svg)$/
8282

8383
// Use vue-cli's default rule for svg in non .vue .js .ts files
8484
config.module.rule('svg').issuer(file => !FILE_RE.test(file))

loader.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const toSFC = require('.')
1010
module.exports = async function(source) {
1111
this.cacheable()
1212

13-
if (this.issuer && this.issuer.endsWith('.css')) {
14-
throw new Error(
15-
`Please configure another loader to handle .svg files imported in .css files\nSee more: https://github.com/egoist/svg-to-vue-component#usage`
16-
)
17-
}
18-
1913
const cb = this.async()
2014
const { svgoConfig } = getOptions(this) || {}
2115

2216
try {
17+
if (this.issuer && this.issuer.endsWith('.css')) {
18+
throw new Error(
19+
`Please configure another loader to handle .svg files imported in .css files\nSee more: https://github.com/egoist/svg-to-vue-component#usage`
20+
)
21+
}
22+
2323
if (svgoConfig !== false) {
2424
const svgo = new SVGO(
2525
await getSvgoConfig(svgoConfig, path.dirname(this.resourcePath))
@@ -33,7 +33,6 @@ module.exports = async function(source) {
3333
}
3434

3535
const { component } = await toSFC(source)
36-
3736
cb(null, component)
3837
} catch (err) {
3938
cb(err)

nuxt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function() {
1111
imageRule.test = /\.(png|jpe?g|gif|webp)$/
1212

1313
// Handle svg files imported by css files
14-
const FILE_RE = /\.(vue|js|ts)$/
14+
const FILE_RE = /\.(vue|js|ts|svg)$/
1515
config.module.rules.push(
1616
Object.assign({}, imageRule, {
1717
issuer: file => !FILE_RE.test(file)

poi.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.name = 'svg-to-vue-component'
33
exports.apply = api => {
44
api.hook('createWebpackChain', config => {
55
// Only convert .svg files that are imported by these files as Vue component
6-
const FILE_RE = /\.(vue|js|ts)$/
6+
const FILE_RE = /\.(vue|js|ts|svg)$/
77

88
// Use vue-cli's default rule for svg in non .vue .js .ts files
99
config.module.rule('svg').issuer(file => !FILE_RE.test(file))
@@ -12,7 +12,9 @@ exports.apply = api => {
1212
config.module
1313
.rule('svg-component')
1414
.test(/\.svg$/)
15-
.issuer(file => FILE_RE.test(file))
15+
.issuer(file => {
16+
return FILE_RE.test(file)
17+
})
1618
.use('vue')
1719
.loader('vue-loader')
1820
.end()

0 commit comments

Comments
 (0)