File tree Expand file tree Collapse file tree 4 files changed +13
-12
lines changed Expand file tree Collapse file tree 4 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ module.exports = {
31
31
test: / \. svg$ / ,
32
32
// If you want to import svg in css files
33
33
// You need to configure another rule to use file-loader for that
34
- issuer: / \. (vue| js| ts)$ / ,
34
+ issuer: / \. (vue| js| ts| svg )$ / ,
35
35
use: [
36
36
// This loader compiles .svg file to .vue file
37
37
// So we use `vue-loader` after it
@@ -78,7 +78,7 @@ In your `vue.config.js`:
78
78
module .exports = {
79
79
chainWebpack (config ) {
80
80
// 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 )$ /
82
82
83
83
// Use vue-cli's default rule for svg in non .vue .js .ts files
84
84
config .module .rule (' svg' ).issuer (file => ! FILE_RE .test (file))
Original file line number Diff line number Diff line change @@ -10,16 +10,16 @@ const toSFC = require('.')
10
10
module . exports = async function ( source ) {
11
11
this . cacheable ( )
12
12
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
-
19
13
const cb = this . async ( )
20
14
const { svgoConfig } = getOptions ( this ) || { }
21
15
22
16
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
+
23
23
if ( svgoConfig !== false ) {
24
24
const svgo = new SVGO (
25
25
await getSvgoConfig ( svgoConfig , path . dirname ( this . resourcePath ) )
@@ -33,7 +33,6 @@ module.exports = async function(source) {
33
33
}
34
34
35
35
const { component } = await toSFC ( source )
36
-
37
36
cb ( null , component )
38
37
} catch ( err ) {
39
38
cb ( err )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ module.exports = function() {
11
11
imageRule . test = / \. ( p n g | j p e ? g | g i f | w e b p ) $ /
12
12
13
13
// Handle svg files imported by css files
14
- const FILE_RE = / \. ( v u e | j s | t s ) $ /
14
+ const FILE_RE = / \. ( v u e | j s | t s | s v g ) $ /
15
15
config . module . rules . push (
16
16
Object . assign ( { } , imageRule , {
17
17
issuer : file => ! FILE_RE . test ( file )
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ exports.name = 'svg-to-vue-component'
3
3
exports . apply = api => {
4
4
api . hook ( 'createWebpackChain' , config => {
5
5
// Only convert .svg files that are imported by these files as Vue component
6
- const FILE_RE = / \. ( v u e | j s | t s ) $ /
6
+ const FILE_RE = / \. ( v u e | j s | t s | s v g ) $ /
7
7
8
8
// Use vue-cli's default rule for svg in non .vue .js .ts files
9
9
config . module . rule ( 'svg' ) . issuer ( file => ! FILE_RE . test ( file ) )
@@ -12,7 +12,9 @@ exports.apply = api => {
12
12
config . module
13
13
. rule ( 'svg-component' )
14
14
. test ( / \. s v g $ / )
15
- . issuer ( file => FILE_RE . test ( file ) )
15
+ . issuer ( file => {
16
+ return FILE_RE . test ( file )
17
+ } )
16
18
. use ( 'vue' )
17
19
. loader ( 'vue-loader' )
18
20
. end ( )
You can’t perform that action at this time.
0 commit comments