CC 4.0 ライセンス

このセクションの内容は、以下のリンクの内容から派生したものであり、CC BY 4.0ライセンスに従います。

特に明記されていない限り、以下の内容は元のコンテンツに基づいて変更および削除された結果とみなすことができます。

CopyRspackPlugin

Rspack 専用

既存の個々のファイルまたはディレクトリ全体をビルドディレクトリにコピーします。

new rspack.CopyRspackPlugin(options);
  • オプション

    • タイプ
    export type CopyRspackPluginOptions = {
      patterns: (
        | string // If input is string, it's the same as { from: `your input string` }
        | {
            from: string;
            to?:
              | string
              | ((pathData: {
                  context: string;
                  absoluteFilename?: string;
                }) => string); // Determine based on `from`
            context?: string; // Default to `context` in Rspack config
            toType?: 'dir' | 'file' | 'template'; // Determine based on `from`
            noErrorOnMissing?: boolean; // Default to false
            force?: boolean; // Default to false
            priority?: number; // Default to 0
            globOptions?: {
              caseSensitiveMatch?: boolean; // Default to true
              dot?: boolean; // Default to true
              ignore?: string[]; // ignore specific path
            };
            transform?: (
              input: Buffer,
              absoluteFilename: string,
            ) => string | Buffer | Promise<string> | Promise<Buffer>;
          }
      )[];
    };
    • デフォルト: undefined
    名前タイプデフォルト説明
    fromstringundefinedコピー操作のソースパス。絶対パス、相対パス、またはglob検索文字列を指定できます。ファイルまたはディレクトリを参照できます。相対パスが渡された場合、`context`設定からの相対パスになります。
    tostring | ((pathData: { context: string; absoluteFilename?: string }) => string)undefinedコピー操作の宛先。絶対パス、相対パス、または`'[name].[hash][ext]'`のようなテンプレート文字列を指定できます。指定しない場合、出力パスと同じになります。
    contextstringundefinedこの設定は、「from」パスのマッチ方法とコピー後の結果の構造を決定します。
    toType'dir'|'file'|'template'undefined`to`のタイプを指定します。ディレクトリ、ファイル、またはrspackのテンプレート名を指定できます。指定しない場合、自動的に推測されます。
    noErrorOnMissingbooleanfalseファイルまたはディレクトリが見つからない場合でもエラーを無視します。
    forcebooleanfalseアセットがすでに存在する場合に上書きするかどうか。
    prioritynumber0`force`が`true`に設定されている場合、一致するファイルが見つかった場合、優先順位の高い方が優先順位の低い方を上書きします。
    globOptionsobjectundefinedglobクエリの構成:`caseSensitiveMatch`は大文字と小文字を区別するかどうかを決定し、`dot`は.で始まるファイルを一致させるかどうかを決定します。 `ignore`は、特定のパスを無視するために使用できるglob形式の文字列の配列です。
    transformfunctionundefinedファイルの内容を変更できます。

rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
  entry: './src/index.js',
  plugins: [
    new rspack.CopyRspackPlugin({
      patterns: [
        {
          from: 'file.txt',
        },
      ],
    }),
  ],
};

上記の設定で実行した結果は、` "dist/file.txt"`になります。

rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
  entry: './src/index.js',
  plugins: [
    new rspack.CopyRspackPlugin({
      patterns: [
        {
          from: 'directory',
        },
      ],
    }),
  ],
};

上記の設定で実行した結果は、`directory`内のファイルとディレクトリが出力パスに配置されます。

rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
  entry: './src/index.js',
  plugins: [
    new rspack.CopyRspackPlugin({
      patterns: [
        {
          from: 'directory/**/*',
          to: 'newdirectory',
        },
      ],
    }),
  ],
};

上記の設定で実行した結果は、`directory`フォルダが出力フォルダ内の`newdirectory`フォルダに移動されます。たとえば、`dist/newdirectory/directory/foo`です。