82 lines
2.7 KiB
JavaScript
82 lines
2.7 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = void 0;
|
||
|
function _plugin() {
|
||
|
const data = require("@parcel/plugin");
|
||
|
_plugin = function () {
|
||
|
return data;
|
||
|
};
|
||
|
return data;
|
||
|
}
|
||
|
function _diagnostic() {
|
||
|
const data = _interopRequireDefault(require("@parcel/diagnostic"));
|
||
|
_diagnostic = function () {
|
||
|
return data;
|
||
|
};
|
||
|
return data;
|
||
|
}
|
||
|
function _utils() {
|
||
|
const data = require("@parcel/utils");
|
||
|
_utils = function () {
|
||
|
return data;
|
||
|
};
|
||
|
return data;
|
||
|
}
|
||
|
function svgo() {
|
||
|
const data = _interopRequireWildcard(require("svgo"));
|
||
|
svgo = function () {
|
||
|
return data;
|
||
|
};
|
||
|
return data;
|
||
|
}
|
||
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
||
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
var _default = exports.default = new (_plugin().Optimizer)({
|
||
|
async loadConfig({
|
||
|
config
|
||
|
}) {
|
||
|
let configFile = await config.getConfig(['svgo.config.js', 'svgo.config.cjs', 'svgo.config.mjs', 'svgo.config.json']);
|
||
|
return configFile === null || configFile === void 0 ? void 0 : configFile.contents;
|
||
|
},
|
||
|
async optimize({
|
||
|
bundle,
|
||
|
contents,
|
||
|
config
|
||
|
}) {
|
||
|
if (!bundle.env.shouldOptimize) {
|
||
|
return {
|
||
|
contents
|
||
|
};
|
||
|
}
|
||
|
let code = await (0, _utils().blobToString)(contents);
|
||
|
let result = svgo().optimize(code, {
|
||
|
plugins: [{
|
||
|
name: 'preset-default',
|
||
|
params: {
|
||
|
overrides: {
|
||
|
// Removing ids could break SVG sprites.
|
||
|
cleanupIDs: false,
|
||
|
// <style> elements and attributes are already minified before they
|
||
|
// are re-inserted by the packager.
|
||
|
minifyStyles: false
|
||
|
}
|
||
|
}
|
||
|
}],
|
||
|
...config
|
||
|
});
|
||
|
if (result.error != null) {
|
||
|
throw new (_diagnostic().default)({
|
||
|
diagnostic: {
|
||
|
message: result.error
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
return {
|
||
|
contents: result.data
|
||
|
};
|
||
|
}
|
||
|
});
|