copy-webpack-plugin
Advanced tools
Comparing version 6.0.4 to 6.1.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [6.1.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.0.4...v6.1.0) (2020-08-31) | ||
### Features | ||
* added `filter` option ([#524](https://github.com/webpack-contrib/copy-webpack-plugin/issues/524)) ([1496f85](https://github.com/webpack-contrib/copy-webpack-plugin/commit/1496f85d2fa5e87dccd0cda92b1343c649f3e5bd)) | ||
* added the `copied` flag to asset info ([09b1dc9](https://github.com/webpack-contrib/copy-webpack-plugin/commit/09b1dc995e476bb7090ebb2c2cbd4b5ebedeaa79)) | ||
* added the `immutable` flag to asset info with hash in name ([#525](https://github.com/webpack-contrib/copy-webpack-plugin/issues/525)) ([a1989d5](https://github.com/webpack-contrib/copy-webpack-plugin/commit/a1989d59b8b0a8caf0b826016e20c82a9ac38aa1)) | ||
* **webpack@5:** improve stats output for `copied` files | ||
### [6.0.4](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.0.3...v6.0.4) (2020-08-29) | ||
@@ -7,0 +17,0 @@ |
@@ -41,7 +41,5 @@ "use strict"; | ||
apply(compiler) { | ||
const plugin = { | ||
name: 'CopyPlugin' | ||
}; | ||
const pluginName = this.constructor.name; | ||
const limit = (0, _pLimit.default)(this.options.concurrency || 100); | ||
compiler.hooks.thisCompilation.tap(plugin, compilation => { | ||
compiler.hooks.thisCompilation.tap(pluginName, compilation => { | ||
const logger = compilation.getLogger('copy-webpack-plugin'); | ||
@@ -96,6 +94,16 @@ compilation.hooks.additionalAssets.tapAsync('copy-webpack-plugin', async callback => { | ||
if (compilation.getAsset(targetPath)) { | ||
const existingAsset = compilation.getAsset(targetPath); | ||
if (existingAsset) { | ||
if (force) { | ||
logger.log(`force updating '${webpackTo}' to compilation assets from '${absoluteFrom}'`); | ||
compilation.updateAsset(targetPath, source); | ||
const info = { | ||
copied: true | ||
}; | ||
if (asset.immutable) { | ||
info.immutable = true; | ||
} | ||
compilation.updateAsset(targetPath, source, info); | ||
return; | ||
@@ -109,3 +117,11 @@ } | ||
logger.log(`writing '${webpackTo}' to compilation assets from '${absoluteFrom}'`); | ||
compilation.emitAsset(targetPath, source); | ||
const info = { | ||
copied: true | ||
}; | ||
if (asset.immutable) { | ||
info.immutable = true; | ||
} | ||
compilation.emitAsset(targetPath, source, info); | ||
}); | ||
@@ -115,2 +131,12 @@ logger.debug('end to adding additional assets'); | ||
}); | ||
if (compilation.hooks.statsPrinter) { | ||
compilation.hooks.statsPrinter.tap(pluginName, stats => { | ||
stats.hooks.print.for('asset.info.copied').tap('copy-webpack-plugin', (copied, { | ||
green, | ||
formatFlag | ||
}) => // eslint-disable-next-line no-undefined | ||
copied ? green(formatFlag('copied')) : undefined); | ||
}); | ||
} | ||
}); | ||
@@ -117,0 +143,0 @@ } |
@@ -20,2 +20,5 @@ { | ||
}, | ||
"filter": { | ||
"instanceof": "Function" | ||
}, | ||
"toType": { | ||
@@ -22,0 +25,0 @@ "enum": ["dir", "file", "template"] |
@@ -100,2 +100,3 @@ "use strict"; | ||
file.immutable = /\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi.test(file.webpackTo); | ||
file.webpackTo = _loaderUtils.default.interpolateName({ | ||
@@ -113,2 +114,3 @@ resourcePath: file.absoluteFrom | ||
logger.log(`transforming path '${file.webpackTo}' for '${file.absoluteFrom}'`); | ||
file.immutable = false; | ||
file.webpackTo = await pattern.transformPath(file.webpackTo, file.absoluteFrom); | ||
@@ -115,0 +117,0 @@ } |
@@ -37,4 +37,16 @@ "use strict"; | ||
return paths // Exclude directories | ||
.filter(item => item.dirent.isFile()).map(item => { | ||
const filteredPaths = (await Promise.all(paths.map(async item => { | ||
// Exclude directories | ||
if (!item.dirent.isFile()) { | ||
return false; | ||
} | ||
if (pattern.filter) { | ||
const isFiltered = await pattern.filter(item.path); | ||
return isFiltered ? item : false; | ||
} | ||
return item; | ||
}))).filter(item => item); | ||
return filteredPaths.map(item => { | ||
const from = item.path; | ||
@@ -41,0 +53,0 @@ logger.debug(`found ${from}`); // `globby`/`fast-glob` return the relative path when the path contains special characters on windows |
{ | ||
"name": "copy-webpack-plugin", | ||
"version": "6.0.4", | ||
"version": "6.1.0", | ||
"description": "Copy files && directories with webpack", | ||
@@ -52,3 +52,3 @@ "license": "MIT", | ||
"p-limit": "^3.0.2", | ||
"schema-utils": "^2.7.0", | ||
"schema-utils": "^2.7.1", | ||
"serialize-javascript": "^4.0.0", | ||
@@ -59,6 +59,6 @@ "webpack-sources": "^1.4.3" | ||
"@babel/cli": "^7.10.5", | ||
"@babel/core": "^7.11.1", | ||
"@babel/core": "^7.11.4", | ||
"@babel/preset-env": "^7.11.0", | ||
"@commitlint/cli": "^9.1.1", | ||
"@commitlint/config-conventional": "^9.1.1", | ||
"@commitlint/cli": "^10.0.0", | ||
"@commitlint/config-conventional": "^10.0.0", | ||
"@webpack-contrib/defaults": "^6.3.0", | ||
@@ -71,3 +71,3 @@ "@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.6.0", | ||
"eslint": "^7.7.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
@@ -77,9 +77,9 @@ "eslint-plugin-import": "^2.22.0", | ||
"is-gzip": "^2.0.0", | ||
"jest": "^26.3.0", | ||
"lint-staged": "^10.2.11", | ||
"jest": "^26.4.2", | ||
"lint-staged": "^10.2.13", | ||
"memfs": "^3.2.0", | ||
"mkdirp": "^1.0.4", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.5", | ||
"standard-version": "^8.0.2", | ||
"prettier": "^2.1.1", | ||
"standard-version": "^9.0.0", | ||
"webpack": "^4.44.1" | ||
@@ -86,0 +86,0 @@ }, |
@@ -83,2 +83,3 @@ <div align="center"> | ||
| [`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. | | ||
@@ -281,2 +282,37 @@ | [`force`](#force) | `{Boolean}` | `false` | Overwrites files already in `compilation.assets` (usually added by other plugins/loaders). | | ||
#### `filter` | ||
Type: `Function` | ||
Default: `undefined` | ||
> ℹ️ To ignore files by path please use the [`globOptions.ignore`]((#globoptions) option. | ||
**webpack.config.js** | ||
```js | ||
const fs = require('fs').promise; | ||
module.exports = { | ||
plugins: [ | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ | ||
from: 'public/**/*', | ||
filter: async (resourcePath) => { | ||
const data = await fs.promises.readFile(resourcePath); | ||
const content = data.toString(); | ||
if (content === 'my-custom-content') { | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}, | ||
], | ||
}), | ||
], | ||
}; | ||
``` | ||
#### `toType` | ||
@@ -283,0 +319,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67769
523
969
Updatedschema-utils@^2.7.1