Skip to content
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

Honor webpack's output.clean option with devMiddleware.writeToDisk #3578

Closed
1 of 2 tasks
jordanbtucker opened this issue Jul 30, 2021 · 1 comment
Closed
1 of 2 tasks

Comments

@jordanbtucker
Copy link

jordanbtucker commented Jul 30, 2021

  • This is a bug
  • This is a modification request

Code

// webpack.config.js
module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    clean: true,
  },
  devServer: {
    devMiddleware: {
      writeToDisk: true,
    },
  },
}
// package.json
{
  "name": "webpack-dev-server-clean-issue",
  "private": true,
  "scripts": {
    "build": "echo 'delete me' > dist/delete-me && webpack",
    "serve": "echo 'delete me' > dist/delete-me && webpack serve"
  },
  "devDependencies": {
    "webpack": "^5.47.1",
    "webpack-cli": "^4.7.2",
    "webpack-dev-server": "^4.0.0-rc.0"
  }
}

Please paste the results of webpack-cli info here, and mention other relevant information

System:
  OS: Windows 10 10.0.19043
  CPU: (16) x64 Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz
  Memory: 16.31 GB / 31.94 GB
Binaries:
  Node: 14.17.3 - ~\scoop\apps\nodejs-lts\current\node.EXE
  npm: 7.20.2 - ~\scoop\apps\nodejs-lts\current\bin\npm.CMD
Browsers:
  Edge: Spartan (44.19041.1023.0), Chromium (92.0.902.55)
  Internet Explorer: 11.0.19041.1
Packages:
  webpack: ^5.47.1 => 5.47.1
  webpack-cli: ^4.7.2 => 4.7.2
  webpack-dev-server: ^4.0.0-rc.0 => 4.0.0-rc.0

Expected Behavior

webpack.config.js uses the output.clean option to clean the output directory before building. When using the webpack command, it works. When using the webpack serve command with devServer.devMiddleware.writeToDisk, it does not work.

There are two scripts in package.json, build and serve. Both scripts add a file named delete-me to the dist directory before running webpack. build runs webpack while serve runs webpack serve. Both scripts should delete the delete-me file.

Actual Behavior

npm run build deletes the delete-me file as expected. However, npm run serve does not.

For Bugs; How can we reproduce the behavior?

Please see https://github.com/jordanbtucker/webpack-dev-server-clean-issue for a minimal reproducible example, including reproduction steps.

@jordanbtucker jordanbtucker changed the title Honor webpack's output.clean option with devMiddlware.writeToDisk Honor webpack's output.clean option with devMiddleware.writeToDisk Jul 30, 2021
@jordanbtucker
Copy link
Author

Actually, this is probably a bug in webpack-dev-middleware, and it looks like there is already an issue open for that. webpack/webpack-dev-middleware#861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant