Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getLocalIdent: (context, localIdentName, localName) => {
// 过滤 uiw 组件库,因为 modules=true 参数,会将 className替换成Hash,导致uiw样式无法加载
const hash = loaderUtils.getHashDigest(context.resourcePath + localIdentName, 'md5', 'base64', 5);
const uiwpath = path.join(process.cwd(), 'node_modules', 'uiw');
if ((new RegExp(`^${uiwpath}`)).test(context.resourcePath)) {
return localName;
}
return localName + hash;
},
},
getLocalIdent: (context, localIdentName, localName) => {
// 过滤 uiw 组件库,因为 modules=true 参数,会将 className替换成Hash,导致uiw样式无法加载
const hash = loaderUtils.getHashDigest(context.resourcePath + localIdentName, 'md5', 'base64', 5);
const uiwpath = path.join(process.cwd(), 'node_modules', 'uiw');
if ((new RegExp(`^${uiwpath}`)).test(context.resourcePath)) {
return localName;
}
return localName + hash;
},
},
// Strip useless helper folder structure
SKIP_FOLDERS.forEach(filter => {
relative = relative.replace(
new RegExp(`(^|/|\\\\)${filter}($|/|\\\\)`),
(match, group1) => group1,
);
});
// Strip all script file extensions
const fileExt = path.parse(relative).ext;
if (SCRIPT_EXTENSIONS.has(fileExt)) {
relative = relative.replace(new RegExp(`${fileExt}$`), '');
}
const hash = loaderUtils.getHashDigest(cleanRequest, HASH_TYPE, DIGEST_TYPE, DIGEST_LENGTH);
const base = path.basename(relative);
const result = `${base}-${hash}`;
return result;
}
export const getCSSModulesLocalIdent = (
context: Context,
localIdentName: string,
localName: string,
options: object
) => {
// Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
const fileNameOrFolder = context.resourcePath.match(
/index\.module\.(css|scss|sass|less)$/ // 此处增加less,其余和原函数一致
)
? '[folder]'
: '[name]';
// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
const hash = loaderUtils.getHashDigest(
path.posix.relative(context.rootContext, context.resourcePath) + localName,
'md5',
'base64',
5
);
// Use loaderUtils to find the file or folder name
const className = loaderUtils.interpolateName(
context,
fileNameOrFolder + '_' + localName + '__' + hash,
options
);
// remove the .module that appears in every classname when based on the file.
return className.replace('.module_', '_');
};
module.exports = function getLocalIdent(
context,
localIdentName,
localName,
options
) {
// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
const hash = loaderUtils.getHashDigest(
context.resourcePath + localName,
'md5',
'base64',
5
);
return idents.get(hash) || getNextIdent(hash);
};
const hashFile = `${destDir}/hash.json`;
if (program.clean) {
if (existsSync(hashFile)) {
unlinkSync(hashFile);
}
}
Object.keys(commonChunks).forEach((chunkName) => {
commonChunks[chunkName].forEach((d) => {
if (allDependencies[d]) {
dllDeps[d] = allDependencies[d];
}
});
});
const newHash = loaderUtils.getHashDigest(JSON.stringify(dllDeps));
let skip = true;
if (existsSync(hashFile)) {
const oldHash = require(hashFile).hash;
console.log('[packing-dll]oldHash:', oldHash);
console.log('[packing-dll]newHash:', newHash);
if (oldHash !== newHash) {
skip = false;
}
} else {
skip = false;
}
if (skip) {
console.log('💛 DllPlugin skipped!');
} else {
result = result.replace(re, (all, hashType, digestType, maxLength) => {
return getHashDigest(content, hashType, digestType, parseInt(maxLength, 10));
});
});
getHashDigest(content) {
return loaderUtils.getHashDigest(content);
}
writeWasmFile(fileName, content, codeGenerationContext) {
const relativeFileName = path.relative(fileName, loader.resourcePath);
const baseName = path.basename(fileName);
const resourceName = loaderUtils.getHashDigest(content, "md5", "hex", 10) + "." + baseName;
loader.emitFile(resourceName, content);
return (loader.options.output.publicPath || "") + resourceName;
}
};
function generateCacheKey(required, currentPath, layers) {
const layersCache = loaderUtils.getHashDigest(layers.toString());
const currentLayerIndex = getCurrentLayerIndex(currentPath, layers);
const currentLayer = layers[currentLayerIndex];
const requiredFile = path.join(required.component, currentLayer.files.main);
const result = layersCache + '-' + currentLayerIndex +
'#' + required.component + JSON.stringify(required.opts);
if (currentPath.length - currentPath.lastIndexOf(requiredFile) === requiredFile.length) {
return result + currentPath;
}
return result;
}