Socket
Socket
Sign inDemoInstall

copy-webpack-plugin

Package Overview
Dependencies
Maintainers
6
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-webpack-plugin - npm Package Compare versions

Comparing version 6.4.0 to 7.0.0

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [7.0.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.4.0...v7.0.0) (2020-12-10)
### ⚠ BREAKING CHANGES
* minimum supported webpack version is `5`
* the `flatten` option was removed in favor `[name].[ext]` value for the `to` option,
* the `transformPath` option was removed in favor `Function` type of the `to` option, look at [examples](https://github.com/webpack-contrib/copy-webpack-plugin#function)
* the `cacheTransform` option was removed in favor `Object` type of the `transform` option, look at [examples](https://github.com/webpack-contrib/copy-webpack-plugin#transform)
* migration on the `compilation.hooks.processAssets` hook
* empty filtered paths throw an error, you can disable this behaviour using the `noErrorOnMissing` option
## [6.4.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.3.2...v6.4.0) (2020-12-07)

@@ -7,0 +19,0 @@

238

dist/index.js

@@ -10,8 +10,4 @@ "use strict";

var _os = _interopRequireDefault(require("os"));
var _crypto = _interopRequireDefault(require("crypto"));
var _webpack = _interopRequireDefault(require("webpack"));
var _schemaUtils = require("schema-utils");

@@ -23,8 +19,4 @@

var _findCacheDir = _interopRequireDefault(require("find-cache-dir"));
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
var _cacache = _interopRequireDefault(require("cacache"));
var _loaderUtils = _interopRequireDefault(require("loader-utils"));

@@ -46,8 +38,2 @@

// webpack 5 exposes the sources property to ensure the right version of webpack-sources is used
const {
RawSource
} = // eslint-disable-next-line global-require
_webpack.default.sources || require("webpack-sources");
const template = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(?::(\d+))?\])|(\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\])|(\[\d+\])/;

@@ -66,7 +52,3 @@

static async createSnapshot(compilation, startTime, dependency) {
if (!compilation.fileSystemInfo) {
return;
} // eslint-disable-next-line consistent-return
// eslint-disable-next-line consistent-return
return new Promise((resolve, reject) => {

@@ -87,7 +69,3 @@ compilation.fileSystemInfo.createSnapshot(startTime, [dependency], // eslint-disable-next-line no-undefined

static async checkSnapshotValid(compilation, snapshot) {
if (!compilation.fileSystemInfo) {
return;
} // eslint-disable-next-line consistent-return
// eslint-disable-next-line consistent-return
return new Promise((resolve, reject) => {

@@ -106,2 +84,5 @@ compilation.fileSystemInfo.checkSnapshotValid(snapshot, (error, isValid) => {

static async runPattern(compiler, compilation, logger, cache, inputPattern, index) {
const {
RawSource
} = compiler.webpack.sources;
const pattern = typeof inputPattern === "string" ? {

@@ -113,4 +94,3 @@ from: inputPattern

pattern.from = _path.default.normalize(pattern.from);
pattern.compilerContext = compiler.context;
pattern.context = _path.default.normalize(typeof pattern.context !== "undefined" ? !_path.default.isAbsolute(pattern.context) ? _path.default.join(pattern.compilerContext, pattern.context) : pattern.context : pattern.compilerContext);
pattern.context = typeof pattern.context === "undefined" ? compiler.context : _path.default.isAbsolute(pattern.context) ? pattern.context : _path.default.join(compiler.context, pattern.context);
logger.log(`starting to process a pattern from '${pattern.from}' using '${pattern.context}' context`);

@@ -156,8 +136,5 @@

}
}; // TODO remove after drop webpack@4
};
pattern.globOptions.fs = inputFileSystem;
if (inputFileSystem.lstat && inputFileSystem.stat && inputFileSystem.lstatSync && inputFileSystem.statSync && inputFileSystem.readdir && inputFileSystem.readdirSync) {
pattern.globOptions.fs = inputFileSystem;
}
switch (pattern.fromType) {

@@ -259,4 +236,9 @@ case "dir":

if (filteredPaths.length === 0) {
// TODO should be error in the next major release
logger.log(`finished to process a pattern from '${pattern.from}' using '${pattern.context}' context to '${pattern.to}'`);
if (pattern.noErrorOnMissing) {
logger.log(`finished to process a pattern from '${pattern.from}' using '${pattern.context}' context to '${pattern.to}'`);
return;
}
const missingError = new Error(`unable to locate '${pattern.glob}' glob after filtering paths`);
compilation.errors.push(missingError);
return;

@@ -271,30 +253,16 @@ }

pattern.to = typeof pattern.to !== "function" ? _path.default.normalize(typeof pattern.to !== "undefined" ? pattern.to : "") : await pattern.to({
pattern.to = typeof pattern.to === "function" ? await pattern.to({
context: pattern.context,
absoluteFilename
});
}) : _path.default.normalize(typeof pattern.to !== "undefined" ? pattern.to : "");
const isToDirectory = _path.default.extname(pattern.to) === "" || pattern.to.slice(-1) === _path.default.sep;
switch (true) {
// if toType already exists
case !!pattern.toType:
break;
const toType = pattern.toType ? pattern.toType : template.test(pattern.to) ? "template" : isToDirectory ? "dir" : "file";
logger.log(`'to' option '${pattern.to}' determinated as '${toType}'`);
case template.test(pattern.to):
pattern.toType = "template";
break;
const relativeFrom = _path.default.relative(pattern.context, absoluteFilename);
case isToDirectory:
pattern.toType = "dir";
break;
let filename = toType === "dir" ? _path.default.join(pattern.to, relativeFrom) : pattern.to;
default:
pattern.toType = "file";
}
logger.log(`'to' option '${pattern.to}' determinated as '${pattern.toType}'`);
const relativeFrom = pattern.flatten ? _path.default.basename(absoluteFilename) : _path.default.relative(pattern.context, absoluteFilename);
let filename = pattern.toType === "dir" ? _path.default.join(pattern.to, relativeFrom) : pattern.to;
if (_path.default.isAbsolute(filename)) {

@@ -305,7 +273,8 @@ filename = _path.default.relative(compiler.options.output.path, filename);

logger.log(`determined that '${from}' should write to '${filename}'`);
const sourceFilename = (0, _normalizePath.default)(_path.default.relative(pattern.compilerContext, absoluteFilename));
const sourceFilename = (0, _normalizePath.default)(_path.default.relative(compiler.context, absoluteFilename));
return {
absoluteFilename,
sourceFilename,
filename
filename,
toType
};

@@ -320,4 +289,6 @@ }));

sourceFilename,
filename
filename,
toType
} = file;
const info = typeof pattern.info === "function" ? pattern.info(file) || {} : pattern.info || {};
const result = {

@@ -328,3 +299,3 @@ absoluteFilename,

force: pattern.force,
info: typeof pattern.info === "function" ? pattern.info(file) || {} : pattern.info || {}
info
}; // If this came from a glob or dir, add it to the file dependencies

@@ -337,8 +308,19 @@

if (cache) {
let cacheEntry;
logger.debug(`getting cache for '${absoluteFilename}'...`);
let cacheEntry;
logger.debug(`getting cache for '${absoluteFilename}'...`);
try {
cacheEntry = await cache.getPromise(`${sourceFilename}|${index}`, null);
} catch (error) {
compilation.errors.push(error);
return;
}
if (cacheEntry) {
logger.debug(`found cache for '${absoluteFilename}'...`);
let isValidSnapshot;
logger.debug(`checking snapshot on valid for '${absoluteFilename}'...`);
try {
cacheEntry = await cache.getPromise(`${sourceFilename}|${index}`, null);
isValidSnapshot = await CopyPlugin.checkSnapshotValid(compilation, cacheEntry.snapshot);
} catch (error) {

@@ -349,23 +331,10 @@ compilation.errors.push(error);

if (cacheEntry) {
logger.debug(`found cache for '${absoluteFilename}'...`);
let isValidSnapshot;
logger.debug(`checking snapshot on valid for '${absoluteFilename}'...`);
try {
isValidSnapshot = await CopyPlugin.checkSnapshotValid(compilation, cacheEntry.snapshot);
} catch (error) {
compilation.errors.push(error);
return;
}
if (isValidSnapshot) {
logger.debug(`snapshot for '${absoluteFilename}' is valid`);
result.source = cacheEntry.source;
} else {
logger.debug(`snapshot for '${absoluteFilename}' is invalid`);
}
if (isValidSnapshot) {
logger.debug(`snapshot for '${absoluteFilename}' is valid`);
result.source = cacheEntry.source;
} else {
logger.debug(`missed cache for '${absoluteFilename}'`);
logger.debug(`snapshot for '${absoluteFilename}' is invalid`);
}
} else {
logger.debug(`missed cache for '${absoluteFilename}'`);
}

@@ -424,65 +393,40 @@

if (pattern.transform) {
logger.log(`transforming content for '${absoluteFilename}'...`);
const buffer = result.source.source();
const transform = typeof pattern.transform === "function" ? {
transformer: pattern.transform
} : pattern.transform;
if (pattern.cacheTransform) {
const defaultCacheKeys = {
version: _package.version,
sourceFilename,
transform: pattern.transform,
contentHash: _crypto.default.createHash("md4").update(buffer).digest("hex"),
index
};
const cacheKeys = `transform|${(0, _serializeJavascript.default)(typeof pattern.cacheTransform.keys === "function" ? await pattern.cacheTransform.keys(defaultCacheKeys, absoluteFilename) : { ...defaultCacheKeys,
...pattern.cacheTransform.keys
})}`;
let cacheItem;
let cacheDirectory;
logger.debug(`getting transformation cache for '${absoluteFilename}'...`); // webpack@5 API
if (transform.transformer) {
logger.log(`transforming content for '${absoluteFilename}'...`);
const buffer = result.source.source();
if (cache) {
cacheItem = cache.getItemCache(cacheKeys, cache.getLazyHashedEtag(result.source));
if (transform.cache) {
const defaultCacheKeys = {
version: _package.version,
sourceFilename,
transform: transform.transformer,
contentHash: _crypto.default.createHash("md4").update(buffer).digest("hex"),
index
};
const cacheKeys = `transform|${(0, _serializeJavascript.default)(typeof transform.cache.keys === "function" ? await transform.cache.keys(defaultCacheKeys, absoluteFilename) : { ...defaultCacheKeys,
...pattern.transform.cache.keys
})}`;
logger.debug(`getting transformation cache for '${absoluteFilename}'...`);
const cacheItem = cache.getItemCache(cacheKeys, cache.getLazyHashedEtag(result.source));
result.source = await cacheItem.getPromise();
} else {
cacheDirectory = pattern.cacheTransform.directory ? pattern.cacheTransform.directory : typeof pattern.cacheTransform === "string" ? pattern.cacheTransform : (0, _findCacheDir.default)({
name: "copy-webpack-plugin"
}) || _os.default.tmpdir();
let cached;
logger.debug(result.source ? `found transformation cache for '${absoluteFilename}'` : `no transformation cache for '${absoluteFilename}'`);
try {
cached = await _cacache.default.get(cacheDirectory, cacheKeys);
} catch (error) {
logger.debug(`no transformation cache for '${absoluteFilename}'...`);
} // eslint-disable-next-line no-undefined
result.source = cached ? new RawSource(cached.data) : undefined;
}
logger.debug(result.source ? `found transformation cache for '${absoluteFilename}'` : `no transformation cache for '${absoluteFilename}'`);
if (!result.source) {
const transformed = await pattern.transform(buffer, absoluteFilename);
result.source = new RawSource(transformed);
logger.debug(`caching transformation for '${absoluteFilename}'...`); // webpack@5 API
if (cache) {
if (!result.source) {
const transformed = await transform.transformer(buffer, absoluteFilename);
result.source = new RawSource(transformed);
logger.debug(`caching transformation for '${absoluteFilename}'...`);
await cacheItem.storePromise(result.source);
} else {
try {
await _cacache.default.put(cacheDirectory, cacheKeys, transformed);
} catch (error) {
compilation.errors.push(error);
return;
}
logger.debug(`cached transformation for '${absoluteFilename}'`);
}
logger.debug(`cached transformation for '${absoluteFilename}'`);
} else {
result.source = new RawSource(await transform.transformer(buffer, absoluteFilename));
}
} else {
result.source = new RawSource(await pattern.transform(buffer, absoluteFilename));
}
}
if (pattern.toType === "template") {
if (toType === "template") {
logger.log(`interpolating template '${filename}' for '${sourceFilename}'...`); // If it doesn't have an extension, remove it from the pattern

@@ -509,11 +453,2 @@ // ie. [name].[ext] or [name][ext] both become [name]

logger.log(`interpolated template '${filename}' for '${sourceFilename}'`);
}
if (pattern.transformPath) {
logger.log(`transforming '${result.filename}' for '${absoluteFilename}'...`); // eslint-disable-next-line no-param-reassign
result.immutable = false; // eslint-disable-next-line no-param-reassign
result.filename = await pattern.transformPath(result.filename, absoluteFilename);
logger.log(`transformed new '${result.filename}' for '${absoluteFilename}'...`);
} // eslint-disable-next-line no-param-reassign

@@ -541,5 +476,7 @@

const logger = compilation.getLogger("copy-webpack-plugin");
const cache = compilation.getCache ? compilation.getCache("CopyWebpackPlugin") : // eslint-disable-next-line no-undefined
undefined;
compilation.hooks.additionalAssets.tapAsync("copy-webpack-plugin", async callback => {
const cache = compilation.getCache("CopyWebpackPlugin");
compilation.hooks.processAssets.tapAsync({
name: "copy-webpack-plugin",
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
}, async (unusedAssets, callback) => {
logger.log("starting to add additional assets...");

@@ -565,12 +502,3 @@ let assets;

force
} = asset; // For old version webpack 4
/* istanbul ignore if */
if (typeof compilation.emitAsset !== "function") {
// eslint-disable-next-line no-param-reassign
compilation.assets[filename] = source;
return;
}
} = asset;
const existingAsset = compilation.getAsset(filename);

@@ -577,0 +505,0 @@

@@ -46,32 +46,35 @@ {

},
"flatten": {
"type": "boolean"
},
"transform": {
"instanceof": "Function"
},
"cacheTransform": {
"anyOf": [
{
"type": "boolean"
"instanceof": "Function"
},
{
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"directory": {
"type": "string",
"absolutePath": true
"transformer": {
"instanceof": "Function"
},
"keys": {
"cache": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
"type": "boolean"
},
{
"instanceof": "Function"
"type": "object",
"additionalProperties": false,
"properties": {
"keys": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
},
{
"instanceof": "Function"
}
]
}
}
}

@@ -78,0 +81,0 @@ ]

{
"name": "copy-webpack-plugin",
"version": "6.4.0",
"version": "7.0.0",
"description": "Copy files && directories with webpack",

@@ -41,8 +41,6 @@ "license": "MIT",

"peerDependencies": {
"webpack": "^4.37.0 || ^5.0.0"
"webpack": "^5.1.0"
},
"dependencies": {
"cacache": "^15.0.5",
"fast-glob": "^3.2.4",
"find-cache-dir": "^3.3.1",
"glob-parent": "^5.1.1",

@@ -54,9 +52,8 @@ "globby": "^11.0.1",

"schema-utils": "^3.0.0",
"serialize-javascript": "^5.0.1",
"webpack-sources": "^1.4.3"
"serialize-javascript": "^5.0.1"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.10",
"@commitlint/cli": "^11.0.0",

@@ -67,3 +64,2 @@ "@commitlint/config-conventional": "^11.0.0",

"babel-jest": "^26.6.3",
"chokidar": "^3.4.3",
"cross-env": "^7.0.2",

@@ -73,3 +69,3 @@ "del": "^6.0.0",

"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-import": "^2.22.1",

@@ -86,3 +82,3 @@ "file-loader": "^6.1.1",

"standard-version": "^9.0.0",
"webpack": "^5.4.0"
"webpack": "^5.10.0"
},

@@ -89,0 +85,0 @@ "keywords": [

@@ -79,17 +79,14 @@ <div align="center">

| Name | Type | Default | Description |
| :-------------------------------------: | :-------------------------: | :---------------------------------------------: | :---------------------------------------------------------------------------------------------------- |
| [`from`](#from) | `{String}` | `undefined` | Glob or path from where we сopy files. |
| [`to`](#to) | `{String\|Function}` | `compiler.options.output` | Output path. |
| [`context`](#context) | `{String}` | `options.context \|\| compiler.options.context` | A path that determines how to interpret the `from` path. |
| [`globOptions`](#globoptions) | `{Object}` | `undefined` | [Options][glob-options] passed to the glob pattern matching library including `ignore` option. |
| [`filter`](#filter) | `{Function}` | `undefined` | Allows to filter copied assets. |
| [`toType`](#totype) | `{String}` | `undefined` | Determinate what is `to` option - directory, file or template. |
| [`force`](#force) | `{Boolean}` | `false` | Overwrites files already in `compilation.assets` (usually added by other plugins/loaders). |
| [`flatten`](#flatten) | `{Boolean}` | `false` | Removes all directory references and only copies file names. |
| [`transform`](#transform) | `{Function}` | `undefined` | Allows to modify the file contents. |
| [`cacheTransform`](#cacheTransform) | `{Boolean\|String\|Object}` | `false` | Enable `transform` caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache. |
| [`transformPath`](#transformpath) | `{Function}` | `undefined` | Allows to modify the writing path. |
| [`noErrorOnMissing`](#noerroronmissing) | `{Boolean}` | `false` | Doesn't generate an error on missing file(s). |
| [`info`](#info) | `{Object\|Function}` | `undefined` | Allows to add assets info. |
| Name | Type | Default | Description |
| :-------------------------------------: | :------------------: | :---------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`from`](#from) | `{String}` | `undefined` | Glob or path from where we сopy files. |
| [`to`](#to) | `{String\|Function}` | `compiler.options.output` | Output path. |
| [`context`](#context) | `{String}` | `options.context \|\| compiler.options.context` | A path that determines how to interpret the `from` path. |
| [`globOptions`](#globoptions) | `{Object}` | `undefined` | [Options][glob-options] passed to the glob pattern matching library including `ignore` option. |
| [`filter`](#filter) | `{Function}` | `undefined` | Allows to filter copied assets. |
| [`toType`](#totype) | `{String}` | `undefined` | Determinate what is `to` option - directory, file or template. |
| [`force`](#force) | `{Boolean}` | `false` | Overwrites files already in `compilation.assets` (usually added by other plugins/loaders). |
| [`transform`](#transform) | `{Object}` | `undefined` | Allows to modify the file contents. Enable `transform` caching. You can use `{ transform: {cache: { key: 'my-cache-key' }} }` to invalidate the cache. |
| [`noErrorOnMissing`](#noerroronmissing) | `{Boolean}` | `false` | Doesn't generate an error on missing file(s). |
| [`info`](#info) | `{Object\|Function}` | `undefined` | Allows to add assets info. |

@@ -233,3 +230,3 @@ #### `from`

to({ context, absoluteFilename }) {
return "dest/newPath";
return "dest/newPath/[name][ext]";
},

@@ -252,5 +249,4 @@ },

from: "src/*.png",
to: "dest/",
to({ context, absoluteFilename }) {
return Promise.resolve("dest/newPath");
return Promise.resolve("dest/newPath/[name][ext]");
},

@@ -472,10 +468,10 @@ },

#### `flatten`
#### `transform`
Type: `Boolean`
Default: `false`
Type: `Function|Object`
Default: `undefined`
Removes all directory references and only copies file names.
Allows to modify the file contents.
> ⚠️ If files have the same name, the result is non-deterministic.
##### `Function`

@@ -490,5 +486,9 @@ **webpack.config.js**

{
from: "src/**/*",
from: "src/*.png",
to: "dest/",
flatten: true,
// The `content` argument is a [`Buffer`](https://nodejs.org/api/buffer.html) object, it could be converted to a `String` to be processed using `content.toString()`
// The `absoluteFrom` argument is a `String`, it is absolute path from where the file is being copied
transform(content, absoluteFrom) {
return optimize(content);
},
},

@@ -501,9 +501,14 @@ ],

#### `transform`
##### `Object`
| Name | Type | Default | Description |
| :-------------------------------: | :-----------------: | :---------: | :--------------------------------------------------------------------------------------------------------------- |
| **[`transformer`](#transformer)** | `{Function}` | `undefined` | Allows to modify the file contents. |
| **[`cache`](#cache)** | `{Boolean\|Object}` | `false` | Enable `transform` caching. You can use `transform: { cache: { key: 'my-cache-key' } }` to invalidate the cache. |
###### `transformer`
Type: `Function`
Default: `undefined`
Allows to modify the file contents.
**webpack.config.js**

@@ -521,4 +526,6 @@

// The `absoluteFrom` argument is a `String`, it is absolute path from where the file is being copied
transform(content, absoluteFrom) {
return optimize(content);
transform: {
transformer(content, absoluteFrom) {
return optimize(content);
},
},

@@ -542,4 +549,6 @@ },

to: "dest/",
transform(content, path) {
return Promise.resolve(optimize(content));
transform: {
transformer(content, path) {
return Promise.resolve(optimize(content));
},
},

@@ -553,11 +562,13 @@ },

#### `cacheTransform`
###### `cache`
Type: `Boolean|String|Object`
Type: `Boolean|Object`
Default: `false`
**webpack.config.js**
Enable/disable and configure caching.
Default path to cache directory: `node_modules/.cache/copy-webpack-plugin`.
##### `Boolean`
###### `Boolean`

@@ -576,6 +587,8 @@ Enables/Disable `transform` caching.

to: "dest/",
transform(content, path) {
return optimize(content);
transform: {
transformer(content, path) {
return optimize(content);
},
cache: true,
},
cacheTransform: true,
},

@@ -588,28 +601,2 @@ ],

##### `String`
Enables `transform` caching and setup cache directory.
**webpack.config.js**
```js
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: "src/*.png",
to: "dest/",
transform(content, path) {
return optimize(content);
},
// Should be absolute
cacheTransform: path.resolve(__dirname, "cache-directory"),
},
],
}),
],
};
```
##### `Object`

@@ -629,12 +616,14 @@

to: "dest/",
transform(content, path) {
return optimize(content);
},
cacheTransform: {
directory: path.resolve(__dirname, "cache-directory"),
keys: {
// May be useful for invalidating cache based on external values
// For example, you can invalid cache based on `process.version` - { node: process.version }
key: "value",
transform: {
transformer(content, path) {
return optimize(content);
},
cache: {
directory: path.resolve(__dirname, "cache-directory"),
keys: {
// May be useful for invalidating cache based on external values
// For example, you can invalid cache based on `process.version` - { node: process.version }
key: "value",
},
},
},

@@ -662,14 +651,16 @@ },

to: "dest/",
transform(content, path) {
return optimize(content);
},
cacheTransform: {
directory: path.resolve(__dirname, "cache-directory"),
keys: (defaultCacheKeys, absoluteFrom) => {
const keys = getCustomCacheInvalidationKeysSync();
transform: {
transformer(content, path) {
return optimize(content);
},
cache: {
directory: path.resolve(__dirname, "cache-directory"),
keys: (defaultCacheKeys, absoluteFrom) => {
const keys = getCustomCacheInvalidationKeysSync();
return {
...defaultCacheKeys,
keys,
};
return {
...defaultCacheKeys,
keys,
};
},
},

@@ -696,14 +687,16 @@ },

to: "dest/",
transform(content, path) {
return optimize(content);
},
cacheTransform: {
directory: path.resolve(__dirname, "cache-directory"),
keys: async (defaultCacheKeys, absoluteFrom) => {
const keys = await getCustomCacheInvalidationKeysAsync();
transform: {
transformer(content, path) {
return optimize(content);
},
cache: {
directory: path.resolve(__dirname, "cache-directory"),
keys: async (defaultCacheKeys, absoluteFrom) => {
const keys = await getCustomCacheInvalidationKeysAsync();
return {
...defaultCacheKeys,
keys,
};
return {
...defaultCacheKeys,
keys,
};
},
},

@@ -718,53 +711,2 @@ },

#### `transformPath`
Type: `Function`
Default: `undefined`
Allows to modify the writing path.
> ⚠️ Don't return directly `\\` in `transformPath` (i.e `path\to\newFile`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
> On Windows, the forward slash and the backward slash are both separators.
> Instead please use `/` or `path` methods.
**webpack.config.js**
```js
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: "src/*.png",
to: "dest/",
transformPath(targetPath, absolutePath) {
return "newPath";
},
},
],
}),
],
};
```
**webpack.config.js**
```js
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: "src/*.png",
to: "dest/",
transformPath(targetPath, absolutePath) {
return Promise.resolve("newPath");
},
},
],
}),
],
};
```
### `noErrorOnMissing`

@@ -1056,2 +998,65 @@

#### Flatten copy
Removes all directory references and only copies file names.
> ⚠️ If files have the same name, the result is non-deterministic.
**webpack.config.js**
```js
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: "src/**/*",
to: "[name].[ext]",
},
],
}),
],
};
```
Result:
```txt
file-1.txt
file-2.txt
nested-file.txt
```
#### Copy in new directory
**webpack.config.js**
```js
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
// When copying files starting with a dot, must specify the toType option
// toType: "file",
to({ context, absoluteFilename }) {
return `newdirectory/${path.relative(context, absoluteFilename)}`;
},
from: "directory",
},
],
}),
],
};
```
Result:
```txt
"newdirectory/file-1.txt",
"newdirectory/nestedfile.txt",
"newdirectory/nested/deep-nested/deepnested.txt",
"newdirectory/nested/nestedfile.txt",
```
## Contributing

@@ -1058,0 +1063,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc