HashedModuleIdsPlugin

이 플러그인은 해시가 모듈의 상대 경로를 기반으로 해 모듈 ID로 4개의 문자열이 생성됩니다.

new webpack.ids.HashedModuleIdsPlugin({
  // 옵션...
});

Options

이 플러그인은 다음 옵션을 지원합니다:

  • context: 이름을 만들기 위한 컨텍스트 디렉터리 (절대 경로).

  • hashFunction: 사용할 해싱 알고리즘, 기본 값은 'md4'입니다. Node.JS의 crypto.createHash의 모든 기능이 지원됩니다.

  • hashDigest: 해시를 생성할 때 사용할 인코딩, 기본 값은 'base64'입니다. Node.JS의 hash.digest의 모든 인코딩이 지원됩니다.

    5.102.1+

    표준 Node.js 인코딩 외에도, 이 플러그인은 URL 안전 해시 값 생성에 유용한 'base64url'도 지원합니다. 커스텀 진법('base26', 'base32', 'base36', 'base49', 'base52', 'base58', 'base62')은 output.hashDigest에서만 사용 가능합니다.

  • hashDigestLength: 사용할 해시 다이제스트의 접두사 길이, 기본 값은 4입니다. 생성된 일부 ID는 모듈 ID 충돌을 피하기 위해 여기에서 지정된 것보다 길 수 있습니다.

Usage

다음은 이 플러그인을 사용하는 방법의 예시입니다:

import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

new webpack.ids.HashedModuleIdsPlugin({
  context: __dirname,
  hashFunction: "sha256",
  hashDigest: "hex",
  hashDigestLength: 20,
});

Using URL-safe encoding (5.102.1+):

import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

new webpack.ids.HashedModuleIdsPlugin({
  context: __dirname,
  hashFunction: "md4",
  hashDigest: "base64url", // URL-safe encoding
  hashDigestLength: 8,
});
Edit this page·

3 Contributors

shaodahongbyzykEslamHiko