From 51599b9fb62469ad98f59ea3200e95d50d8b54b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Wed, 4 Nov 2020 22:38:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#47184=20feat(copy-?= =?UTF-8?q?webpack-plugin):=20assets=20filtering=20and=20v6.2=20by=20@pete?= =?UTF-8?q?rblazejewicz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove /// node types reference - filter option - minor version bump https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.1.1...v6.2.0 Thanks! --- .../copy-webpack-plugin-tests.ts | 18 ++++++++++++++++++ types/copy-webpack-plugin/index.d.ts | 10 ++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts b/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts index 671b541caa066c..e32a856e3c95bb 100644 --- a/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts +++ b/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts @@ -1,10 +1,12 @@ import { Configuration } from 'webpack'; import CopyPlugin = require('copy-webpack-plugin'); import path = require('path'); +import fs = require('fs'); const _: Configuration = { plugins: [ // basic + new CopyPlugin(), new CopyPlugin({ patterns: [ { from: 'source', to: 'dest' }, @@ -65,6 +67,22 @@ const _: Configuration = { }, ], }), + // filter + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'file.txt'), + filter: (resourcePath) => { + const data = fs.readFileSync(resourcePath); + const content = data.toString(); + if (content === 'my-custom-content') { + return false; + } + return true; + }, + }, + ], + }), // to new CopyPlugin({ patterns: [ diff --git a/types/copy-webpack-plugin/index.d.ts b/types/copy-webpack-plugin/index.d.ts index 0a2cb9fb6bc746..528dc23a17d6d8 100644 --- a/types/copy-webpack-plugin/index.d.ts +++ b/types/copy-webpack-plugin/index.d.ts @@ -1,12 +1,9 @@ -// Type definitions for copy-webpack-plugin 6.0 +// Type definitions for copy-webpack-plugin 6.2 // Project: https://github.com/webpack-contrib/copy-webpack-plugin // Definitions by: flying-sheep // avin-kavish // Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - import { Plugin } from 'webpack'; interface ObjectPattern { @@ -39,6 +36,11 @@ interface ObjectPattern { */ globOptions?: object; + /** + * Allows to filter copied assets. + */ + filter?: (resourcePath: string) => boolean; + /** * How to interpret `to`. default: undefined * `file` - if 'to' has extension or 'from' is file.