How to use the loader-utils.getHashDigest function in loader-utils

To help you get started, we’ve selected a few loader-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uiwjs / uiw-admin / scripts / conf / webpack.config.prod.js View on Github external
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;
                  },
                },
github uiwjs / uiw-admin / scripts / conf / webpack.config.dev.js View on Github external
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;
                  },
                },
github strues / boldr / internal / webpack / plugins / ChunkNames.js View on Github external
// 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;
}
github feflow / builder-webpack4 / src / util.ts View on Github external
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_', '_');
};
github bvaughn / react-window / website / config / utils / getLocalIdent.js View on Github external
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);
};
github packingjs / packing / src / bin / packing-dll.js View on Github external
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 {
github JetBrains / svg-sprite-loader / lib / utils / hash-tokens.js View on Github external
result = result.replace(re, (all, hashType, digestType, maxLength) => {
      return getHashDigest(content, hashType, digestType, parseInt(maxLength, 10));
    });
  });
github packingjs / packing / src / lib / plugin.js View on Github external
getHashDigest(content) {
    return loaderUtils.getHashDigest(content);
  }
github MichaReiser / speedy.js / packages / loader / index.js View on Github external
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;
        }
    };
github rebem / layers-loader / lib / runner.js View on Github external
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;
}