Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #319 from saguijs/clean-only-on-build-action
Browse files Browse the repository at this point in the history
Run clean only when the action is BUILD 🏗
  • Loading branch information
pirelenito authored Mar 23, 2017
2 parents 3c3fca5 + be278e5 commit 4247d8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/webpack/presets/clean.js
Original file line number Diff line number Diff line change
@@ -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
})
]
] : []
}
}
}
13 changes: 11 additions & 2 deletions src/webpack/presets/clean.spec.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
})
})

0 comments on commit 4247d8d

Please sign in to comment.