diff --git a/README.md b/README.md index 212ac7ae..bb359e14 100644 --- a/README.md +++ b/README.md @@ -499,11 +499,10 @@ module.exports = { ### Options -| Name | Type | Default | Description | -| :---------------------------------: | :---------: | :------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------ | -| [`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 | +| Name | Type | Default | Description | +| :-------------------: | :--------: | :------------------------: | :------------------------------------------------------------------------------- | +| [`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 | #### `ignore` @@ -529,20 +528,6 @@ module.exports = { }; ``` -#### `copyUnmodified` - -Copies files, regardless of modification when using watch or `webpack-dev-server`. All files are copied on first build, regardless of this option. - -> ℹ️ 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 -module.exports = { - plugins: [new CopyPlugin([...patterns], { copyUnmodified: true })], -}; -``` - ## Contributing Please take a moment to read our contributing guidelines if you haven't yet done so. diff --git a/src/index.js b/src/index.js index 4e976ff0..6c1396d9 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,6 @@ class CopyPlugin { apply(compiler) { const fileDependencies = new Set(); const contextDependencies = new Set(); - const written = {}; let context; @@ -44,14 +43,12 @@ class CopyPlugin { const globalRef = { logger, compilation, - written, fileDependencies, contextDependencies, context, inputFileSystem: compiler.inputFileSystem, output: compiler.options.output.path, ignore: this.options.ignore || [], - copyUnmodified: this.options.copyUnmodified, concurrency: this.options.concurrency, }; diff --git a/src/options.json b/src/options.json index 0a000440..fe7582fe 100644 --- a/src/options.json +++ b/src/options.json @@ -101,12 +101,6 @@ }, "ignore": { "type": "array" - }, - "logLevel": { - "type": "string" - }, - "copyUnmodified": { - "type": "boolean" } } } diff --git a/src/postProcessPattern.js b/src/postProcessPattern.js index cf62bccf..bc95494a 100644 --- a/src/postProcessPattern.js +++ b/src/postProcessPattern.js @@ -15,14 +15,7 @@ import { stat, readFile } from './utils/promisify'; /* eslint-disable no-param-reassign */ export default function postProcessPattern(globalRef, pattern, file) { - const { - logger, - compilation, - fileDependencies, - written, - inputFileSystem, - copyUnmodified, - } = globalRef; + const { logger, compilation, fileDependencies, inputFileSystem } = globalRef; logger.debug(`getting stats for '${file.absoluteFrom}' to write to assets`); @@ -148,30 +141,7 @@ export default function postProcessPattern(globalRef, pattern, file) { return content; }) .then((content) => { - const hash = loaderUtils.getHashDigest(content); const targetPath = normalizePath(file.webpackTo); - const targetAbsolutePath = normalizePath(file.absoluteFrom); - - if ( - !copyUnmodified && - written[targetPath] && - written[targetPath][targetAbsolutePath] && - written[targetPath][targetAbsolutePath] === hash - ) { - logger.log( - `skipping '${file.webpackTo}', because content hasn't changed` - ); - - return; - } - - logger.debug(`adding '${file.webpackTo}' for tracking content changes`); - - if (!written[targetPath]) { - written[targetPath] = {}; - } - - written[targetPath][targetAbsolutePath] = hash; if (compilation.assets[targetPath] && !file.force) { logger.log(`skipping '${file.webpackTo}', because it already exists`); diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 1725a319..9acb3619 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -385,9 +385,9 @@ describe('apply function', () => { .catch(done); }); - it('only include files that have changed', (done) => { + it('should include files that have changed when `from` is a file', (done) => { runChange({ - expectedAssetKeys: ['tempfile1.txt'], + expectedAssetKeys: ['tempfile1.txt', 'tempfile2.txt'], newFileLoc1: path.join(FIXTURES_DIR, 'watch', 'tempfile1.txt'), newFileLoc2: path.join(FIXTURES_DIR, 'watch', 'tempfile2.txt'), patterns: [ @@ -403,9 +403,9 @@ describe('apply function', () => { .catch(done); }); - it('only include files that have changed', (done) => { + it('should include all files when `from` is a directory', (done) => { runChange({ - expectedAssetKeys: ['tempfile1.txt'], + expectedAssetKeys: ['.gitkeep', 'tempfile1.txt', 'tempfile2.txt'], newFileLoc1: path.join( FIXTURES_DIR, 'watch', @@ -428,37 +428,9 @@ describe('apply function', () => { .catch(done); }); - it('include all files if copyUnmodified is true', (done) => { + it('should include all files when `from` is a glob', (done) => { runChange({ - expectedAssetKeys: ['tempfile1.txt', 'tempfile2.txt', '.gitkeep'], - newFileLoc1: path.join( - FIXTURES_DIR, - 'watch', - 'directory', - 'tempfile1.txt' - ), - newFileLoc2: path.join( - FIXTURES_DIR, - 'watch', - 'directory', - 'tempfile2.txt' - ), - options: { - copyUnmodified: true, - }, - patterns: [ - { - from: 'directory', - }, - ], - }) - .then(done) - .catch(done); - }); - - it('copy only changed files', (done) => { - runChange({ - expectedAssetKeys: ['dest1/tempfile1.txt'], + expectedAssetKeys: ['dest1/tempfile1.txt', 'dest1/tempfile2.txt'], newFileLoc1: path.join( FIXTURES_DIR, 'watch', @@ -483,9 +455,14 @@ describe('apply function', () => { .catch(done); }); - it('copy only changed files (multiple patterns)', (done) => { + it('should include all files when multiple patterns used', (done) => { runChange({ - expectedAssetKeys: ['dest1/tempfile1.txt', 'dest2/tempfile1.txt'], + expectedAssetKeys: [ + 'dest1/tempfile1.txt', + 'dest1/tempfile2.txt', + 'dest2/tempfile1.txt', + 'dest2/tempfile2.txt', + ], newFileLoc1: path.join( FIXTURES_DIR, 'watch', @@ -515,11 +492,12 @@ describe('apply function', () => { .catch(done); }); - it('copy only changed files (multiple patterns with difference context)', (done) => { + it('should include all files when multiple patterns with difference contexts', (done) => { runChange({ expectedAssetKeys: [ 'dest1/tempfile1.txt', 'dest2/directory/tempfile1.txt', + 'dest2/tempfile2.txt', ], newFileLoc1: path.join( FIXTURES_DIR, @@ -543,60 +521,5 @@ describe('apply function', () => { .then(done) .catch(done); }); - - it('copy only changed files (multiple patterns with difference context 1)', (done) => { - runChange({ - expectedAssetKeys: [ - 'dest1/directory/tempfile1.txt', - 'dest2/tempfile1.txt', - ], - newFileLoc1: path.join( - FIXTURES_DIR, - 'watch', - 'directory', - 'tempfile1.txt' - ), - newFileLoc2: path.join(FIXTURES_DIR, 'watch', 'tempfile2.txt'), - patterns: [ - { - from: '**/*.txt', - to: 'dest1', - }, - { - context: 'directory', - from: '**/*.txt', - to: 'dest2', - }, - ], - }) - .then(done) - .catch(done); - }); - - it('copy only changed files (multiple patterns with difference context 2)', (done) => { - runChange({ - expectedAssetKeys: ['dest1/tempfile1.txt'], - newFileLoc1: path.join(FIXTURES_DIR, 'watch', 'tempfile1.txt'), - newFileLoc2: path.join( - FIXTURES_DIR, - 'watch', - 'directory', - 'tempfile2.txt' - ), - patterns: [ - { - from: '**/*.txt', - to: 'dest1', - }, - { - context: 'directory', - from: '**/*.txt', - to: 'dest2', - }, - ], - }) - .then(done) - .catch(done); - }); }); });