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

Run clean only when the action is BUILD 🏗 #319

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})