Skip to content

Commit 2a3b51c

Browse files
committed
WIP SVGO 2.x
1 parent 0bb1ea2 commit 2a3b51c

File tree

3 files changed

+113
-346
lines changed

3 files changed

+113
-346
lines changed

index.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
const SVGO = require('svgo');
1+
const { optimize } = require('svgo');
22
const { getOptions } = require('loader-utils');
33
const { version } = require('vue');
44
const semverMajor = require('semver/functions/major')
55

6-
module.exports = async function (svg) {
7-
const callback = this.async();
6+
module.exports = function vueSvgLoader(svg) {
87
const { svgo: svgoConfig } = getOptions(this) || {};
98

109
if (svgoConfig !== false) {
11-
const svgo = new SVGO(svgoConfig);
12-
13-
try {
14-
({ data: svg } = await svgo.optimize(svg, {
15-
path: this.resourcePath,
16-
}));
17-
} catch (error) {
18-
callback(error);
19-
return;
20-
}
10+
({ data: svg } = optimize(svg, {
11+
path: this.resourcePath,
12+
...svgoConfig
13+
}));
2114
}
2215

2316
if (semverMajor(version) === 2) {
2417
svg = svg.replace('<svg', '<svg v-on="$listeners"');
2518
}
2619

27-
callback(null, `<template>${svg}</template>`)
20+
return `<template>${svg}</template>`;
2821
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"loader-utils": "^2.0.0",
2020
"semver": "^7.3.4",
21-
"svgo": "^1.3.2"
21+
"svgo": "^2.1.0"
2222
},
2323
"peerDependencies": {
2424
"vue": "^2.5.0 || ^3.0.0-0"

0 commit comments

Comments
 (0)