Skip to content

When using the "clean" option, empty the dir, but don't remove it entirely #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
12 changes: 2 additions & 10 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,9 @@ class ConfigGenerator {

if (this.webpackConfig.cleanupOutput) {
plugins.push(
new CleanWebpackPlugin([this.webpackConfig.outputPath], {
new CleanWebpackPlugin(['**/*'], {
root: this.webpackConfig.outputPath,
verbose: false,
/*
* Instead of passing the "root" option and then making
* the first argument (this.webpackConfig.outputPath) relative
* to that (e.g. "builds"), we pass the absolute path as
* the first argument. To the plugin, this looks like a
* path that is "outside of the project root". This flag
* says to ignore that.
*/
allowExternal: true
})
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ function emptyTmpDir() {

function touchFileInOutputDir(filename, webpackConfig) {
const fullPath = path.join(webpackConfig.outputPath, filename);
fs.ensureDirSync(path.dirname(fullPath));

fs.writeFileSync(
fullPath,
''
Expand Down
4 changes: 4 additions & 0 deletions test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,16 @@ module.exports = {
config.addEntry('main', './js/no_require');
config.cleanupOutputBeforeBuild();
testSetup.touchFileInOutputDir('file.txt', config);
testSetup.touchFileInOutputDir('deeper/other.txt', config);

testSetup.runWebpack(config, (webpackAssert) => {
// make sure the file was cleaned up!
webpackAssert.assertOutputFileDoesNotExist(
'file.txt'
);
webpackAssert.assertOutputFileDoesNotExist(
'deeper/other.txt'
);

done();
});
Expand Down