diff --git a/lib/webpack/client.js b/lib/webpack/client.js index b7f21758be..af01ba309c 100644 --- a/lib/webpack/client.js +++ b/lib/webpack/client.js @@ -1,6 +1,7 @@ const path = require('path'); const webpackNiceLog = require('webpack-nicelog'); const {StatsWriterPlugin} = require('webpack-stats-plugin'); +const cleanWebpackPlugin = require('clean-webpack-plugin'); const createBaseConfig = require('./base'); module.exports = function createClientConfig(props) { @@ -8,6 +9,11 @@ module.exports = function createClientConfig(props) { config.entry('main').add(path.resolve(__dirname, '../core/clientEntry.js')); + const {outDir} = props; + config + .plugin('clean') + .use(cleanWebpackPlugin, [outDir, {verbose: false, allowExternal: true}]); + // write webpack stats object to a file so we can // programmatically refer to the correct bundle path in Node.js server. config diff --git a/package.json b/package.json index 6b2a272a39..336ebae2a8 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "babel-preset-react": "^6.24.1", "chalk": "^2.4.1", "chokidar": "^2.0.4", + "clean-webpack-plugin": "^0.1.19", "commander": "^2.16.0", "connect-history-api-fallback": "^1.5.0", "css-loader": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index 5492a2cc91..e98375889c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1521,6 +1521,12 @@ clean-css@4.1.x: dependencies: source-map "0.5.x" +clean-webpack-plugin@^0.1.19: + version "0.1.19" + resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-0.1.19.tgz#ceda8bb96b00fe168e9b080272960d20fdcadd6d" + dependencies: + rimraf "^2.6.1" + cli-boxes@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143"