1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/svg-sprite-loader/lib/utils/is-module-should-be-extract...

36 lines
948 B
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
const defaults = require('../config');
const normalizeRule = require('./normalize-rule');
const spriteLoaderPath = require.resolve('../loader');
/**
* @param {NormalModule} module
* @return {boolean}
*/
function isModuleShouldBeExtracted(module) {
const { request, issuer, loaders } = module;
let rule = null;
if (Array.isArray(loaders) && loaders.length > 0) {
// Find loader rule
rule = loaders.map(normalizeRule).find(data => data.loader === spriteLoaderPath);
}
let issuerResource = null;
if (issuer) {
// webpack 1 compat
issuerResource = typeof issuer === 'string' ? issuer : issuer.resource;
}
if (typeof request === 'string' && (!request.includes(spriteLoaderPath) || !rule)) {
return false;
}
return !!(
(issuer && defaults.EXTRACTABLE_MODULE_ISSUER_PATTERN.test(issuerResource)) ||
(rule && rule.options && rule.options.extract)
);
}
module.exports = isModuleShouldBeExtracted;