chushihua

This commit is contained in:
li
2026-01-26 23:20:48 +08:00
commit 7b5aab0206
22521 changed files with 3300090 additions and 0 deletions
+243
View File
@@ -0,0 +1,243 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="4.6.0"></a>
# [4.6.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.5.4...v4.6.0) (2018-10-31)
### Bug Fixes
* handle undefined and null as stats value ([#302](https://github.com/webpack-contrib/copy-webpack-plugin/issues/302)) ([78c5d12](https://github.com/webpack-contrib/copy-webpack-plugin/commit/78c5d12))
### Features
* add support for target path transform ([#284](https://github.com/webpack-contrib/copy-webpack-plugin/issues/284)) ([7fe0c06](https://github.com/webpack-contrib/copy-webpack-plugin/commit/7fe0c06))
<a name="4.5.4"></a>
## [4.5.4](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.5.3...v4.5.4) (2018-10-18)
### Bug Fixes
* **processPattern:** don't add `'glob'` as directory when it is a file (`contextDependencies`) ([#296](https://github.com/webpack-contrib/copy-webpack-plugin/issues/296)) ([5670926](https://github.com/webpack-contrib/copy-webpack-plugin/commit/5670926))
<a name="4.5.3"></a>
## [4.5.3](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.5.2...v4.5.3) (2018-10-10)
### Bug Fixes
* **processPattern:** add `glob` directory context to `contextDependencies` ([#290](https://github.com/webpack-contrib/copy-webpack-plugin/issues/290)) ([5fa69db](https://github.com/webpack-contrib/copy-webpack-plugin/commit/5fa69db))
<a name="4.5.2"></a>
## [4.5.2](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.5.1...v4.5.2) (2018-06-26)
### Bug Fixes
* allow square brackets in path ([#264](https://github.com/webpack-contrib/copy-webpack-plugin/issues/264)) ([3ef5b6c](https://github.com/webpack-contrib/copy-webpack-plugin/commit/3ef5b6c)), closes [#231](https://github.com/webpack-contrib/copy-webpack-plugin/issues/231)
<a name="4.5.1"></a>
## [4.5.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.5.0...v4.5.1) (2018-03-09)
### Bug Fixes
* **package:** update `cacache` v10.0.1...10.0.4 (`dependencies`) ([#238](https://github.com/webpack-contrib/copy-webpack-plugin/issues/238)) ([0b288f9](https://github.com/webpack-contrib/copy-webpack-plugin/commit/0b288f9))
### Performance Improvements
* **index:** switch to `md4` for content hashing ([#239](https://github.com/webpack-contrib/copy-webpack-plugin/issues/239)) ([2be8191](https://github.com/webpack-contrib/copy-webpack-plugin/commit/2be8191))
<a name="4.5.0"></a>
# [4.5.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.4.3...v4.5.0) (2018-03-02)
### Features
* **processPattern:** add support for `{RegExp)` matches (`pattern.test`) ([#235](https://github.com/webpack-contrib/copy-webpack-plugin/issues/235)) ([1861730](https://github.com/webpack-contrib/copy-webpack-plugin/commit/1861730))
<a name="4.4.3"></a>
## [4.4.3](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.4.2...v4.4.3) (2018-03-01)
### Bug Fixes
* **index:** `tapable` deprecation warnings (`webpack >= v4.0.0`) ([#234](https://github.com/webpack-contrib/copy-webpack-plugin/issues/234)) ([445d548](https://github.com/webpack-contrib/copy-webpack-plugin/commit/445d548))
<a name="4.4.2"></a>
## [4.4.2](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.4.1...v4.4.2) (2018-02-23)
### Bug Fixes
* **src/:** don't escape non-glob patterns ([#230](https://github.com/webpack-contrib/copy-webpack-plugin/issues/230)) ([0eb2cd5](https://github.com/webpack-contrib/copy-webpack-plugin/commit/0eb2cd5))
<a name="4.4.1"></a>
## [4.4.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.4.0...v4.4.1) (2018-02-08)
### Bug Fixes
* replace `pify` with simpler promise helpers ([#221](https://github.com/webpack-contrib/copy-webpack-plugin/issues/221)) ([dadac24](https://github.com/webpack-contrib/copy-webpack-plugin/commit/dadac24))
<a name="4.4.0"></a>
# [4.4.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.3.1...v4.4.0) (2018-02-08)
### Bug Fixes
* **package:** add `prepare` script ([9bf0d99](https://github.com/webpack-contrib/copy-webpack-plugin/commit/9bf0d99))
* **preProcessPatterns:** support glob context paths with special characters ([#208](https://github.com/webpack-contrib/copy-webpack-plugin/issues/208)) ([ea0c05f](https://github.com/webpack-contrib/copy-webpack-plugin/commit/ea0c05f))
* support `webpack >= v4.0.0` ([6a16b3c](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6a16b3c))
### Features
* use `compiler.inputFileSystem` instead `fs` ([#205](https://github.com/webpack-contrib/copy-webpack-plugin/issues/205)) ([158f821](https://github.com/webpack-contrib/copy-webpack-plugin/commit/158f821))
<a name="4.3.1"></a>
## [4.3.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.3.0...v4.3.1) (2017-12-22)
### Bug Fixes
* `cache` behaviour ([#196](https://github.com/webpack-contrib/copy-webpack-plugin/issues/196)) ([6beb89e](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6beb89e))
* `cache` option behaviour ([3b088d0](https://github.com/webpack-contrib/copy-webpack-plugin/commit/3b088d0))
<a name="4.3.0"></a>
# [4.3.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.2.4...v4.3.0) (2017-12-14)
### Features
* add option to cache `pattern.transform` (`pattern.cache`) ([#176](https://github.com/webpack-contrib/copy-webpack-plugin/issues/176)) ([20c143b](https://github.com/webpack-contrib/copy-webpack-plugin/commit/20c143b))
* option for caching `transform` function ([48c19ff](https://github.com/webpack-contrib/copy-webpack-plugin/commit/48c19ff))
<a name="4.2.4"></a>
## [4.2.4](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.2.3...v4.2.4) (2017-12-14)
### Refactoring
* refactor: use native `{Promise}` instead of `bluebird` ([#178](https://github.com/webpack-contrib/copy-webpack-plugin/issues/178)) ([a508f14](https://github.com/webpack-contrib/copy-webpack-plugin/commit/a508f14))
<a name="4.2.3"></a>
## [4.2.3](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.2.2...v4.2.3) (2017-11-23)
<a name="4.2.2"></a>
## [4.2.2](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.2.0...v4.2.2) (2017-11-23)
### Bug Fixes
* copying same file to multiple targets ([#165](https://github.com/webpack-contrib/copy-webpack-plugin/issues/165)) ([43a9870](https://github.com/webpack-contrib/copy-webpack-plugin/commit/43a9870))
<a name="4.2.0"></a>
# [4.2.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.1.1...v4.2.0) (2017-10-19)
### Features
* add `context` option (`options.context`) ([#149](https://github.com/webpack-contrib/copy-webpack-plugin/issues/149)) ([10cd1a2](https://github.com/webpack-contrib/copy-webpack-plugin/commit/10cd1a2))
* allow async transforms ([#111](https://github.com/webpack-contrib/copy-webpack-plugin/issues/111)) ([8794e5f](https://github.com/webpack-contrib/copy-webpack-plugin/commit/8794e5f))
* Plugin context option ([5c54e92](https://github.com/webpack-contrib/copy-webpack-plugin/commit/5c54e92)), closes [#148](https://github.com/webpack-contrib/copy-webpack-plugin/issues/148)
* support `{String}` patterns ([#155](https://github.com/webpack-contrib/copy-webpack-plugin/issues/155)) ([b6c2e66](https://github.com/webpack-contrib/copy-webpack-plugin/commit/b6c2e66))
* Support simple string patterns ([056a60b](https://github.com/webpack-contrib/copy-webpack-plugin/commit/056a60b)), closes [#150](https://github.com/webpack-contrib/copy-webpack-plugin/issues/150)
<a name="4.1.1"></a>
## [4.1.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.1.0...v4.1.1) (2017-10-05)
### Chore
* Update dependencies for NSP security advisory ([#151](https://github.com/webpack-contrib/copy-webpack-plugin/issues/151)) ([6d4346e](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6d4346e))
- Reference issue: https://nodesecurity.io/advisories/minimatch_regular-expression-denial-of-service
<a name="4.1.0"></a>
# [4.1.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v2.1.3...v4.1.0) (2017-09-29)
### Bug Fixes
* Changed default ignore glob to ignore dot files ([#80](https://github.com/webpack-contrib/copy-webpack-plugin/issues/80)) ([08b69a4](https://github.com/webpack-contrib/copy-webpack-plugin/commit/08b69a4))
* Fixed glob as object ([1b2c21a](https://github.com/webpack-contrib/copy-webpack-plugin/commit/1b2c21a))
* Improved Windows compatibility ([#85](https://github.com/webpack-contrib/copy-webpack-plugin/issues/85)) ([ad62899](https://github.com/webpack-contrib/copy-webpack-plugin/commit/ad62899))
* Memory leak in watch mode and use Set for performance ([#130](https://github.com/webpack-contrib/copy-webpack-plugin/issues/130)) ([de46fde](https://github.com/webpack-contrib/copy-webpack-plugin/commit/de46fde))
* subdirectory errors in blob patterns ([c2720d0](https://github.com/webpack-contrib/copy-webpack-plugin/commit/c2720d0))
### Features
* Added non-wildcard glob support ([405d1ec](https://github.com/webpack-contrib/copy-webpack-plugin/commit/405d1ec))
* Added transform method to patterns ([#77](https://github.com/webpack-contrib/copy-webpack-plugin/issues/77)) ([6371eb1](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6371eb1))
<a name="4.0.1"></a>
## [4.0.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v2.1.3...v4.0.1) (2017-09-29)
### Bug Fixes
* Fixed glob as object ([1b2c21a](https://github.com/webpack-contrib/copy-webpack-plugin/commit/1b2c21a))
* Improved Windows compatibility ([#85](https://github.com/webpack-contrib/copy-webpack-plugin/issues/85)) ([ad62899](https://github.com/webpack-contrib/copy-webpack-plugin/commit/ad62899))
* subdirectory errors in blob patterns ([c2720d0](https://github.com/webpack-contrib/copy-webpack-plugin/commit/c2720d0))
### Features
* Added non-wildcard glob support ([405d1ec](https://github.com/webpack-contrib/copy-webpack-plugin/commit/405d1ec))
* Added transform method to patterns ([#77](https://github.com/webpack-contrib/copy-webpack-plugin/issues/77)) ([6371eb1](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6371eb1))
<a name="4.0.0"></a>
## [4.0.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v4.0.0...v3.0.1) (2016-10-23)
### Bug Fixes
* Changed default ignore glob to ignore dot files ([#80](https://github.com/webpack-contrib/copy-webpack-plugin/issues/80)) ([08b69a4](https://github.com/webpack-contrib/copy-webpack-plugin/commit/08b69a4))
### Features
* Added transform method to patterns ([6371eb1](https://github.com/webpack-contrib/copy-webpack-plugin/commit/6371eb1))
+20
View File
@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+449
View File
@@ -0,0 +1,449 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Copy Webpack Plugin</h1>
<p>Copies individual files or entire directories to the build directory</p>
</div>
<h2 align="center">Install</h2>
```bash
npm i -D copy-webpack-plugin
```
<h2 align="center">Usage</h2>
**webpack.config.js**
```js
const CopyWebpackPlugin = require('copy-webpack-plugin')
const config = {
plugins: [
new CopyWebpackPlugin([ ...patterns ], options)
]
}
```
> ️ If you want `webpack-dev-server` to write files to the output directory during development, you can force it with the [`write-file-webpack-plugin`](https://github.com/gajus/write-file-webpack-plugin).
### `Patterns`
A simple pattern looks like this
```js
{ from: 'source', to: 'dest' }
```
Or, in case of just a `from` with the default destination, you can also use a `{String}` as shorthand instead of an `{Object}`
```js
'source'
```
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[`from`](#from)|`{String\|Object}`|`undefined`|Globs accept [minimatch options](https://github.com/isaacs/minimatch)|
|[`fromArgs`](#fromArgs)|`{Object}`|`{ cwd: context }`|See the [`node-glob` options](https://github.com/isaacs/node-glob#options) in addition to the ones below|
|[`to`](#to)|`{String\|Object}`|`undefined`|Output root if `from` is file or dir, resolved glob path if `from` is glob|
|[`toType`](#toType)|`{String}`|``|[toType Options](#totype)|
|[`test`](#test)|`{RegExp}`|``|Pattern for extracting elements to be used in `to` templates|
|[`force`](#force)|`{Boolean}`|`false`|Overwrites files already in `compilation.assets` (usually added by other plugins/loaders)|
|[`ignore`](#ignore)|`{Array}`|`[]`|Globs to ignore for this pattern|
|`flatten`|`{Boolean}`|`false`|Removes all directory references and only copies file names.⚠️ If files have the same name, the result is non-deterministic|
|[`transform`](#transform)|`{Function\|Promise}`|`(content, path) => content`|Function or Promise that modifies file contents before copying|
|[`transformPath`](#transformPath)|`{Function\|Promise}`|`(targetPath, sourcePath) => path`|Function or Promise that modifies file writing path|
|[`cache`](#cache)|`{Boolean\|Object}`|`false`|Enable `transform` caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache|
|[`context`](#context)|`{String}`|`options.context \|\| compiler.options.context`|A path that determines how to interpret the `from` path|
### `from`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
'relative/path/to/file.ext',
'/absolute/path/to/file.ext',
'relative/path/to/dir',
'/absolute/path/to/dir',
'**/*',
{ glob: '\*\*/\*', dot: true }
], options)
]
```
### `to`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{ from: '**/*', to: 'relative/path/to/dest/' },
{ from: '**/*', to: '/absolute/path/to/dest/' }
], options)
]
```
### `toType`
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`'dir'`**|`{String}`|`undefined`|If `from` is directory, `to` has no extension or ends in `'/'`|
|**`'file'`**|`{String}`|`undefined`|If `to` has extension or `from` is file|
|**`'template'`**|`{String}`|`undefined`|If `to` contains [a template pattern](https://github.com/webpack-contrib/file-loader#placeholders)|
#### `'dir'`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'path/to/file.txt',
to: 'directory/with/extension.ext',
toType: 'dir'
}
], options)
]
```
#### `'file'`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'path/to/file.txt',
to: 'file/without/extension',
toType: 'file'
},
], options)
]
```
#### `'template'`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/',
to: 'dest/[name].[hash].[ext]',
toType: 'template'
}
], options)
]
```
### `test`
Defines a `{RegExp}` to match some parts of the file path.
These capture groups can be reused in the name property using `[N]` placeholder.
Note that `[0]` will be replaced by the entire path of the file,
whereas `[1]` will contain the first capturing parenthesis of your `{RegExp}`
and so on...
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: '*/*',
to: '[1]-[2].[hash].[ext]',
test: /([^/]+)\/(.+)\.png$/
}
], options)
]
```
### `force`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{ from: 'src/**/*', to: 'dest/', force: true }
], options)
]
```
### `ignore`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{ from: 'src/**/*', to: 'dest/', ignore: [ '*.js' ] }
], options)
]
```
### `flatten`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{ from: 'src/**/*', to: 'dest/', flatten: true }
], options)
]
```
### `transform`
#### `{Function}`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/*.png',
to: 'dest/',
transform (content, path) {
return optimize(content)
}
}
], options)
]
```
#### `{Promise}`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/*.png',
to: 'dest/',
transform (content, path) {
return Promise.resolve(optimize(content))
}
}
], options)
]
```
### `transformPath`
#### `{Function}`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/*.png',
to: 'dest/',
transformPath (targetPath, absolutePath) {
return 'newPath';
}
}
], options)
]
```
#### `{Promise}`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/*.png',
to: 'dest/',
transform (targePath, absolutePath) {
return Promise.resolve('newPath')
}
}
], options)
]
```
### `cache`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{
from: 'src/*.png',
to: 'dest/',
transform (content, path) {
return optimize(content)
},
cache: true
}
], options)
]
```
### `context`
**webpack.config.js**
```js
[
new CopyWebpackPlugin([
{ from: 'src/*.txt', to: 'dest/', context: 'app/' }
], options)
]
```
<h2 align="center">Options</h2>
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[`debug`](#debug)|`{String}`|**`'warning'`**|[Debug Options](#debug)|
|[`ignore`](#ignore)|`{Array}`|`[]`|Array of globs to ignore (applied to `from`)|
|[`context`](#context)|`{String}`|`compiler.options.context`|A path that determines how to interpret the `from` path, shared for all patterns|
|[`copyUnmodified`](#copyUnmodified)|`{Boolean}`|`false`|Copies files, regardless of modification when using watch or `webpack-dev-server`. All files are copied on first build, regardless of this option|
### `debug`
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`'info'`**|`{String\|Boolean}`|`false`|File location and read info|
|**`'debug'`**|`{String}`|`false`|Very detailed debugging info|
|**`'warning'`**|`{String}`|`true`|Only warnings|
#### `'info'`
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ debug: 'info' }
)
]
```
#### `'debug'`
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ debug: 'debug' }
)
]
```
#### `'warning' (default)`
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ debug: true }
)
]
```
### `ignore`
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ ignore: [ '*.js', '*.css' ] }
)
]
```
### `context`
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ context: '/app' }
)
]
```
### `copyUnmodified`
> ️ By default, we only copy **modified** files during a `webpack --watch` or `webpack-dev-server` build. Setting this option to `true` will copy all files.
**webpack.config.js**
```js
[
new CopyWebpackPlugin(
[ ...patterns ],
{ copyUnmodified: true }
)
]
```
<h2 align="center">Maintainers</h2>
<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/bebraw">
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
</br>
Juho Vepsäläinen
</a>
</td>
<td align="center">
<a href="https://github.com/d3viant0ne">
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
</br>
Joshua Wiens
</a>
</td>
<td align="center">
<a href="https://github.com/michael-ciniawsky">
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
</br>
Michael Ciniawsky
</a>
</td>
<td align="center">
<a href="https://github.com/evilebottnawi">
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
</br>
Alexander Krasnoyarov
</a>
</td>
</tr>
<tbody>
</table>
[npm]: https://img.shields.io/npm/v/copy-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/copy-webpack-plugin
[node]: https://img.shields.io/node/v/copy-webpack-plugin.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/copy-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/copy-webpack-plugin
[test]: https://secure.travis-ci.org/webpack-contrib/copy-webpack-plugin.svg
[test-url]: http://travis-ci.org/webpack-contrib/copy-webpack-plugin
[cover]: https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/copy-webpack-plugin
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
+240
View File
@@ -0,0 +1,240 @@
'use strict';
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _preProcessPattern = require('./preProcessPattern');
var _preProcessPattern2 = _interopRequireDefault(_preProcessPattern);
var _processPattern = require('./processPattern');
var _processPattern2 = _interopRequireDefault(_processPattern);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function CopyWebpackPlugin() {
var patterns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!Array.isArray(patterns)) {
throw new Error('[copy-webpack-plugin] patterns must be an array');
}
// Defaults debug level to 'warning'
options.debug = options.debug || 'warning';
// Defaults debugging to info if only true is specified
if (options.debug === true) {
options.debug = 'info';
}
var debugLevels = ['warning', 'info', 'debug'];
var debugLevelIndex = debugLevels.indexOf(options.debug);
function log(msg, level) {
if (level === 0) {
msg = 'WARNING - ' + msg;
} else {
level = level || 1;
}
if (level <= debugLevelIndex) {
console.log('[copy-webpack-plugin] ' + msg); // eslint-disable-line no-console
}
}
function warning(msg) {
log(msg, 0);
}
function info(msg) {
log(msg, 1);
}
function debug(msg) {
log(msg, 2);
}
var apply = function apply(compiler) {
var fileDependencies = void 0;
var contextDependencies = void 0;
var written = {};
var context = void 0;
if (!options.context) {
context = compiler.options.context;
} else if (!_path2.default.isAbsolute(options.context)) {
context = _path2.default.join(compiler.options.context, options.context);
} else {
context = options.context;
}
var emit = function emit(compilation, cb) {
debug('starting emit');
var callback = function callback() {
debug('finishing emit');
cb();
};
fileDependencies = [];
contextDependencies = [];
var globalRef = {
info: info,
debug: debug,
warning: warning,
compilation: compilation,
written: written,
fileDependencies: fileDependencies,
contextDependencies: contextDependencies,
context: context,
inputFileSystem: compiler.inputFileSystem,
output: compiler.options.output.path,
ignore: options.ignore || [],
copyUnmodified: options.copyUnmodified,
concurrency: options.concurrency
};
if (globalRef.output === '/' && compiler.options.devServer && compiler.options.devServer.outputPath) {
globalRef.output = compiler.options.devServer.outputPath;
}
var tasks = [];
patterns.forEach(function (pattern) {
tasks.push(Promise.resolve().then(function () {
return (0, _preProcessPattern2.default)(globalRef, pattern);
})
// Every source (from) is assumed to exist here
.then(function (pattern) {
return (0, _processPattern2.default)(globalRef, pattern);
}));
});
Promise.all(tasks).catch(function (err) {
compilation.errors.push(err);
}).then(function () {
return callback();
});
};
var afterEmit = function afterEmit(compilation, cb) {
debug('starting after-emit');
var callback = function callback() {
debug('finishing after-emit');
cb();
};
var compilationFileDependencies = void 0;
var addFileDependency = void 0;
if (Array.isArray(compilation.fileDependencies)) {
compilationFileDependencies = new Set(compilation.fileDependencies);
addFileDependency = function addFileDependency(file) {
return compilation.fileDependencies.push(file);
};
} else {
compilationFileDependencies = compilation.fileDependencies;
addFileDependency = function addFileDependency(file) {
return compilation.fileDependencies.add(file);
};
}
var compilationContextDependencies = void 0;
var addContextDependency = void 0;
if (Array.isArray(compilation.contextDependencies)) {
compilationContextDependencies = new Set(compilation.contextDependencies);
addContextDependency = function addContextDependency(file) {
return compilation.contextDependencies.push(file);
};
} else {
compilationContextDependencies = compilation.contextDependencies;
addContextDependency = function addContextDependency(file) {
return compilation.contextDependencies.add(file);
};
}
// Add file dependencies if they're not already tracked
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = fileDependencies[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var file = _step.value;
if (compilationFileDependencies.has(file)) {
debug('not adding ' + file + ' to change tracking, because it\'s already tracked');
} else {
debug('adding ' + file + ' to change tracking');
addFileDependency(file);
}
}
// Add context dependencies if they're not already tracked
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = contextDependencies[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _context = _step2.value;
if (compilationContextDependencies.has(_context)) {
debug('not adding ' + _context + ' to change tracking, because it\'s already tracked');
} else {
debug('adding ' + _context + ' to change tracking');
addContextDependency(_context);
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
callback();
};
if (compiler.hooks) {
var plugin = { name: 'CopyPlugin' };
compiler.hooks.emit.tapAsync(plugin, emit);
compiler.hooks.afterEmit.tapAsync(plugin, afterEmit);
} else {
compiler.plugin('emit', emit);
compiler.plugin('after-emit', afterEmit);
}
};
return {
apply: apply
};
}
CopyWebpackPlugin['default'] = CopyWebpackPlugin;
module.exports = CopyWebpackPlugin;
+139
View File
@@ -0,0 +1,139 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = preProcessPattern;
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _isGlob = require('is-glob');
var _isGlob2 = _interopRequireDefault(_isGlob);
var _escape = require('./utils/escape');
var _escape2 = _interopRequireDefault(_escape);
var _isObject = require('./utils/isObject');
var _isObject2 = _interopRequireDefault(_isObject);
var _promisify = require('./utils/promisify');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// https://www.debuggex.com/r/VH2yS2mvJOitiyr3
var isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?hash(:\w+)?(:\d+)?\])|(\[\d+\])/;
function preProcessPattern(globalRef, pattern) {
var info = globalRef.info,
debug = globalRef.debug,
warning = globalRef.warning,
context = globalRef.context,
inputFileSystem = globalRef.inputFileSystem,
fileDependencies = globalRef.fileDependencies,
contextDependencies = globalRef.contextDependencies,
compilation = globalRef.compilation;
pattern = typeof pattern === 'string' ? {
from: pattern
} : Object.assign({}, pattern);
pattern.to = pattern.to || '';
pattern.context = pattern.context || context;
if (!_path2.default.isAbsolute(pattern.context)) {
pattern.context = _path2.default.join(context, pattern.context);
}
pattern.ignore = globalRef.ignore.concat(pattern.ignore || []);
info('processing from: \'' + pattern.from + '\' to: \'' + pattern.to + '\'');
switch (true) {
case !!pattern.toType:
// if toType already exists
break;
case isTemplateLike.test(pattern.to):
pattern.toType = 'template';
break;
case _path2.default.extname(pattern.to) === '' || pattern.to.slice(-1) === '/':
pattern.toType = 'dir';
break;
default:
pattern.toType = 'file';
}
debug('determined \'' + pattern.to + '\' is a \'' + pattern.toType + '\'');
// If we know it's a glob, then bail early
if ((0, _isObject2.default)(pattern.from) && pattern.from.glob) {
pattern.fromType = 'glob';
var fromArgs = Object.assign({}, pattern.from);
delete fromArgs.glob;
pattern.fromArgs = fromArgs;
pattern.glob = (0, _escape2.default)(pattern.context, pattern.from.glob);
pattern.absoluteFrom = _path2.default.resolve(pattern.context, pattern.from.glob);
return Promise.resolve(pattern);
}
if (_path2.default.isAbsolute(pattern.from)) {
pattern.absoluteFrom = pattern.from;
} else {
pattern.absoluteFrom = _path2.default.resolve(pattern.context, pattern.from);
}
debug('determined \'' + pattern.from + '\' to be read from \'' + pattern.absoluteFrom + '\'');
var noStatsHandler = function noStatsHandler() {
// If from doesn't appear to be a glob, then log a warning
if ((0, _isGlob2.default)(pattern.from) || pattern.from.indexOf('*') !== -1) {
pattern.fromType = 'glob';
pattern.glob = (0, _escape2.default)(pattern.context, pattern.from);
} else {
var msg = 'unable to locate \'' + pattern.from + '\' at \'' + pattern.absoluteFrom + '\'';
var warningMsg = '[copy-webpack-plugin] ' + msg;
// only display the same message once
if (compilation.errors.indexOf(warningMsg) === -1) {
warning(msg);
compilation.errors.push(warningMsg);
}
pattern.fromType = 'nonexistent';
}
};
return (0, _promisify.stat)(inputFileSystem, pattern.absoluteFrom).catch(function () {
return noStatsHandler();
}).then(function (stat) {
if (!stat) {
noStatsHandler();
return pattern;
}
if (stat.isDirectory()) {
pattern.fromType = 'dir';
pattern.context = pattern.absoluteFrom;
contextDependencies.push(pattern.absoluteFrom);
pattern.glob = (0, _escape2.default)(pattern.absoluteFrom, '**/*');
pattern.absoluteFrom = _path2.default.join(pattern.absoluteFrom, '**/*');
pattern.fromArgs = {
dot: true
};
} else if (stat.isFile()) {
pattern.fromType = 'file';
pattern.context = _path2.default.dirname(pattern.absoluteFrom);
pattern.glob = (0, _escape2.default)(pattern.absoluteFrom);
pattern.fromArgs = {
dot: true
};
fileDependencies.push(pattern.absoluteFrom);
} else if (!pattern.fromType) {
info('Unrecognized file type for ' + pattern.from);
}
return pattern;
});
}
+138
View File
@@ -0,0 +1,138 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = processPattern;
var _globby = require('globby');
var _globby2 = _interopRequireDefault(_globby);
var _pLimit = require('p-limit');
var _pLimit2 = _interopRequireDefault(_pLimit);
var _isGlob = require('is-glob');
var _isGlob2 = _interopRequireDefault(_isGlob);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _minimatch = require('minimatch');
var _minimatch2 = _interopRequireDefault(_minimatch);
var _writeFile = require('./writeFile');
var _writeFile2 = _interopRequireDefault(_writeFile);
var _isObject = require('./utils/isObject');
var _isObject2 = _interopRequireDefault(_isObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function processPattern(globalRef, pattern) {
var info = globalRef.info,
debug = globalRef.debug,
output = globalRef.output,
concurrency = globalRef.concurrency,
contextDependencies = globalRef.contextDependencies;
var globArgs = Object.assign({
cwd: pattern.context
}, pattern.fromArgs || {});
if (pattern.fromType === 'nonexistent') {
return Promise.resolve();
}
var limit = (0, _pLimit2.default)(concurrency || 100);
info('begin globbing \'' + pattern.glob + '\' with a context of \'' + pattern.context + '\'');
return (0, _globby2.default)(pattern.glob, globArgs).then(function (paths) {
return Promise.all(paths.map(function (from) {
return limit(function () {
var file = {
force: pattern.force,
absoluteFrom: _path2.default.resolve(pattern.context, from)
};
file.relativeFrom = _path2.default.relative(pattern.context, file.absoluteFrom);
if (pattern.flatten) {
file.relativeFrom = _path2.default.basename(file.relativeFrom);
}
// This is so webpack is able to watch the directory and when
// a new file is added it triggeres a rebuild
var contextPath = _path2.default.dirname(_path2.default.resolve(from));
if (contextDependencies.indexOf(contextPath) === -1 && (0, _isGlob2.default)(pattern.glob)) {
contextDependencies.push(contextPath);
}
debug('found ' + from);
// Check the ignore list
var il = pattern.ignore.length;
while (il--) {
var ignoreGlob = pattern.ignore[il];
var globParams = {
dot: true,
matchBase: true
};
var glob = void 0;
if (typeof ignoreGlob === 'string') {
glob = ignoreGlob;
} else if ((0, _isObject2.default)(ignoreGlob)) {
glob = ignoreGlob.glob || '';
var ignoreGlobParams = Object.assign({}, ignoreGlob);
delete ignoreGlobParams.glob;
// Overwrite minimatch defaults
globParams = Object.assign(globParams, ignoreGlobParams);
} else {
glob = '';
}
debug('testing ' + glob + ' against ' + file.relativeFrom);
if ((0, _minimatch2.default)(file.relativeFrom, glob, globParams)) {
info('ignoring \'' + file.relativeFrom + '\', because it matches the ignore glob \'' + glob + '\'');
return Promise.resolve();
} else {
debug(glob + ' doesn\'t match ' + file.relativeFrom);
}
}
// Change the to path to be relative for webpack
if (pattern.toType === 'dir') {
file.webpackTo = _path2.default.join(pattern.to, file.relativeFrom);
} else if (pattern.toType === 'file') {
file.webpackTo = pattern.to || file.relativeFrom;
} else if (pattern.toType === 'template') {
file.webpackTo = pattern.to;
file.webpackToRegExp = pattern.test;
}
if (_path2.default.isAbsolute(file.webpackTo)) {
if (output === '/') {
throw '[copy-webpack-plugin] Using older versions of webpack-dev-server, devServer.outputPath must be defined to write to absolute paths';
}
file.webpackTo = _path2.default.relative(output, file.webpackTo);
}
// ensure forward slashes
file.webpackTo = file.webpackTo.replace(/\\/g, '/');
info('determined that \'' + from + '\' should write to \'' + file.webpackTo + '\'');
return (0, _writeFile2.default)(globalRef, pattern, file);
});
}));
});
}
+35
View File
@@ -0,0 +1,35 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = escape;
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function escape(context, from) {
if (from && _path2.default.isAbsolute(from)) {
return from;
} else {
// Ensure context is escaped before globbing
// Handles special characters in paths
var absoluteContext = _path2.default.resolve(context).replace(/[\*|\?|\!|\(|\)|\[|\]|\{|\}]/g, function (substring) {
return '[' + substring + ']';
});
if (!from) {
return absoluteContext;
}
// Cannot use path.join/resolve as it "fixes" the path separators
if (absoluteContext.endsWith('/')) {
return '' + absoluteContext + from;
} else {
return absoluteContext + '/' + from;
}
}
}
+9
View File
@@ -0,0 +1,9 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (val) {
return Object.prototype.toString.call(val) === '[object Object]' ? true : false;
};
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var stat = exports.stat = function stat(inputFileSystem, path) {
return new Promise(function (resolve, reject) {
inputFileSystem.stat(path, function (err, stats) {
if (err) {
reject(err);
}
resolve(stats);
});
});
};
var readFile = exports.readFile = function readFile(inputFileSystem, path) {
return new Promise(function (resolve, reject) {
inputFileSystem.readFile(path, function (err, stats) {
if (err) {
reject(err);
}
resolve(stats);
});
});
};
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (inputFileSystem, path) {
return new Promise(function (resolve, reject) {
inputFileSystem.readFile(path, function (err, stats) {
if (err) {
return reject(err);
}
return resolve(stats);
});
});
};
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (inputFileSystem, path) {
return new Promise(function (resolve, reject) {
inputFileSystem.readFile(path, function (err, stats) {
if (err) {
return reject(err);
}
return resolve(stats);
});
});
};
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (inputFileSystem, path) {
return new Promise(function (resolve, reject) {
inputFileSystem.stat(path, function (err, stats) {
if (err) {
return reject(err);
}
return resolve(stats);
});
});
};
+153
View File
@@ -0,0 +1,153 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = writeFile;
var _loaderUtils = require('loader-utils');
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _cacache = require('cacache');
var _cacache2 = _interopRequireDefault(_cacache);
var _serializeJavascript = require('serialize-javascript');
var _serializeJavascript2 = _interopRequireDefault(_serializeJavascript);
var _package = require('../package.json');
var _findCacheDir = require('find-cache-dir');
var _findCacheDir2 = _interopRequireDefault(_findCacheDir);
var _promisify = require('./utils/promisify');
var _crypto = require('crypto');
var _crypto2 = _interopRequireDefault(_crypto);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function writeFile(globalRef, pattern, file) {
var info = globalRef.info,
debug = globalRef.debug,
compilation = globalRef.compilation,
fileDependencies = globalRef.fileDependencies,
written = globalRef.written,
inputFileSystem = globalRef.inputFileSystem,
copyUnmodified = globalRef.copyUnmodified;
return (0, _promisify.stat)(inputFileSystem, file.absoluteFrom).then(function (stat) {
// We don't write empty directories
if (stat.isDirectory()) {
return;
}
// If this came from a glob, add it to the file watchlist
if (pattern.fromType === 'glob') {
fileDependencies.push(file.absoluteFrom);
}
info('reading ' + file.absoluteFrom + ' to write to assets');
return (0, _promisify.readFile)(inputFileSystem, file.absoluteFrom).then(function (content) {
if (pattern.transform) {
var transform = function transform(content, absoluteFrom) {
return pattern.transform(content, absoluteFrom);
};
if (pattern.cache) {
if (!globalRef.cacheDir) {
globalRef.cacheDir = (0, _findCacheDir2.default)({ name: 'copy-webpack-plugin' });
}
var cacheKey = pattern.cache.key ? pattern.cache.key : (0, _serializeJavascript2.default)({
name: _package.name,
version: _package.version,
pattern: pattern,
hash: _crypto2.default.createHash('md4').update(content).digest('hex')
});
return _cacache2.default.get(globalRef.cacheDir, cacheKey).then(function (result) {
return result.data;
}, function () {
return Promise.resolve().then(function () {
return transform(content, file.absoluteFrom);
}).then(function (content) {
return _cacache2.default.put(globalRef.cacheDir, cacheKey, content).then(function () {
return content;
});
});
});
}
content = transform(content, file.absoluteFrom);
}
return content;
}).then(function (content) {
if (pattern.toType === 'template') {
info('interpolating template \'' + file.webpackTo + '\' for \'' + file.relativeFrom + '\'');
// If it doesn't have an extension, remove it from the pattern
// ie. [name].[ext] or [name][ext] both become [name]
if (!_path2.default.extname(file.relativeFrom)) {
file.webpackTo = file.webpackTo.replace(/\.?\[ext\]/g, '');
}
file.webpackTo = _loaderUtils2.default.interpolateName({ resourcePath: file.absoluteFrom }, file.webpackTo, {
content: content,
regExp: file.webpackToRegExp,
context: pattern.context
});
}
return content;
}).then(function (content) {
if (pattern.transformPath) {
return Promise.resolve(pattern.transformPath(file.webpackTo, file.absoluteFrom)).then(function (newPath) {
file.webpackTo = newPath;
}).then(function () {
return content;
});
}
return content;
}).then(function (content) {
var hash = _loaderUtils2.default.getHashDigest(content);
if (!copyUnmodified && written[file.absoluteFrom] && written[file.absoluteFrom]['hash'] === hash && written[file.absoluteFrom]['webpackTo'] === file.webpackTo) {
info('skipping \'' + file.webpackTo + '\', because it hasn\'t changed');
return;
} else {
debug('added ' + hash + ' to written tracking for \'' + file.absoluteFrom + '\'');
written[file.absoluteFrom] = {
hash: hash,
webpackTo: file.webpackTo
};
}
if (compilation.assets[file.webpackTo] && !file.force) {
info('skipping \'' + file.webpackTo + '\', because it already exists');
return;
}
info('writing \'' + file.webpackTo + '\' to compilation assets from \'' + file.absoluteFrom + '\'');
compilation.assets[file.webpackTo] = {
size: function size() {
return stat.size;
},
source: function source() {
return content;
}
};
});
});
}
+56
View File
@@ -0,0 +1,56 @@
{
"name": "copy-webpack-plugin",
"version": "4.6.0",
"description": "Copy files && directories with webpack",
"author": "Len Boyette",
"license": "MIT",
"main": "dist/index.js",
"engines": {
"node": ">= 4"
},
"files": [
"dist"
],
"scripts": {
"lint": "eslint src/ tests/",
"prepare": "npm run build",
"release": "standard-version",
"pretest": "npm run lint && npm run build && npm run build:tests",
"test": "mocha compiled_tests/",
"build": "babel src/ --out-dir dist/",
"build:tests": "babel tests/ --out-dir compiled_tests/ && rimraf compiled_tests/helpers && ncp tests/helpers compiled_tests/helpers && node scripts/createSpecialDirectory.js"
},
"dependencies": {
"globby": "^7.1.1",
"cacache": "^10.0.4",
"find-cache-dir": "^1.0.0",
"serialize-javascript": "^1.4.0",
"is-glob": "^4.0.0",
"loader-utils": "^1.1.0",
"minimatch": "^3.0.4",
"p-limit": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.4.0",
"enhanced-resolve": "^3.4.1",
"eslint": "^2.9.0",
"is-gzip": "^2.0.0",
"mkdirp": "^0.5.1",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"rimraf": "^2.6.2",
"standard-version": "^4.2.0"
},
"homepage": "https://github.com/webpack-contrib/copy-webpack-plugin",
"bugs": "https://github.com/webpack-contrib/copy-webpack-plugin/issues",
"repository": "https://github.com/webpack-contrib/copy-webpack-plugin.git",
"keywords": [
"webpack",
"plugin",
"transfer",
"move",
"copy"
]
}