From be278e5e3ada42e05b1f9c0069b8b27c87168c1f Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Thu, 23 Mar 2017 16:05:45 +0100 Subject: [PATCH] =?UTF-8?q?Run=20clean=20only=20when=20the=20action=20is?= =?UTF-8?q?=20BUILD=20=F0=9F=8F=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/webpack/presets/clean.js | 7 ++++--- src/webpack/presets/clean.spec.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/webpack/presets/clean.js b/src/webpack/presets/clean.js index 7a0cf30..edd1dcb 100644 --- a/src/webpack/presets/clean.js +++ b/src/webpack/presets/clean.js @@ -1,15 +1,16 @@ import CleanWebpackPlugin from 'clean-webpack-plugin' +import actions from '../../actions' export default { name: 'clean', - configure ({ projectPath }) { + configure ({ projectPath, action }) { return { - plugins: [ + plugins: action === actions.BUILD ? [ new CleanWebpackPlugin(['dist'], { root: projectPath, verbose: false }) - ] + ] : [] } } } diff --git a/src/webpack/presets/clean.spec.js b/src/webpack/presets/clean.spec.js index 6291822..8423918 100644 --- a/src/webpack/presets/clean.spec.js +++ b/src/webpack/presets/clean.spec.js @@ -1,11 +1,12 @@ import { expect } from 'chai' import CleanWebpackPlugin from 'clean-webpack-plugin' import preset from './clean' +import actions from '../../actions' describe('clean webpack preset', function () { - it('should configure CleanWebpackPlugin', function () { + it('should configure CleanWebpackPlugin when action is BUILD', function () { const projectPath = 'a/demo/path' - const config = preset.configure({ projectPath }) + const config = preset.configure({ projectPath, action: actions.BUILD }) const commons = config.plugins.filter((preset) => preset instanceof CleanWebpackPlugin) expect(commons.length).equal(1) @@ -15,4 +16,12 @@ describe('clean webpack preset', function () { expect(cleanWebpackPlugin.options.verbose).to.eql(false) expect(cleanWebpackPlugin.options.root).to.eql(projectPath) }) + + it('should not configure CleanWebpackPlugin by default', function () { + const projectPath = 'a/demo/path' + const config = preset.configure({ projectPath }) + + const commons = config.plugins.filter((preset) => preset instanceof CleanWebpackPlugin) + expect(commons.length).equal(0) + }) })