UNPKG

@aniyajs/rotor

Version:

基于webpack5开发的一款专注于打包、运行的工具

35 lines (30 loc) 1.06 kB
const loaderUtils = require("loader-utils"); const path = require("path"); module.exports = function getLocalIdent( context, localIdentName, localName, options, ) { // 使用文件名或文件夹名,基于一些使用index.js / index.module.(css|scss|sass)项目风格 const fileNameOrFolder = context.resourcePath.match( /index\.module\.(css|sass|scss)/, ) ? "[folder]" : "[name]"; // 使用文件名或文件夹名,基于一些使用index.js / index.module.(css|scss|sass)项目风格 const hash = loaderUtils.getHashDigest( path.posix.relative(context.rootContext, context.resourcePath) + localName, "md5", "base64", 5, ); // 使用loaderUtils查找文件或文件夹名称 const className = loaderUtils.interpolateName( context, fileNameOrFolder + "_" + localName + "__" + hash, options, ); // 删除基于文件时出现在每个类名中的.module,并用"_"替换所有"."。 return className.replace(".module_", "_").replace(/\./g, "_"); };