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

Delete old [hash] files in --watch mode #9243

Closed
abriginets opened this issue Jun 10, 2019 · 2 comments
Closed

Delete old [hash] files in --watch mode #9243

abriginets opened this issue Jun 10, 2019 · 2 comments

Comments

@abriginets
Copy link

Feature request

Hello. I'm using the next syntax for generating bundle filenames:

output: {
    filename: 'bundle/[name].[hash].js',
},
new MiniCssExtractPlugin({
    filename: 'bundle/[name].[hash].css',
}),

And the problem here is that if I use webpack in --watch mode then in every next build I'll get new app.552720a12c71ab7e7eb5.js in my /bundle directory without deleting previously built files.
I tried googling a fix for this small problem of mine and met this old question on StackOverflow where people suggested two options:

  1. Deleting whole directory (which is not inapropriate in --watch mode) and rebuild from the scratch
  2. Using webpack-clean-obsolete-chunks plugin, which seems to be unmaintained since most of dependencies are outdated

Since [hash] syntax is Webpack's functionality, maybe it should watch /dist directory and replace old bundle builds with the new ones in --watch mode?

I'm sorry if this question was already asked and I missed it but there is really not so much information about it.

What is the expected behavior?

Replace old hash files with new ones in --watch mode

What is motivation or use case for adding/changing the behavior?

It'll speed up development process by not wasting much time on cleaning /dist dir and rebuild the whole project from the scratch.

How should this be implemented in your opinion?

I.e. we have webpack pattern bundle/[name].[hash].js which can be matched by regex. If a similar file was spotted in build process at dist dir, then Webpack should replace already existing file with newly generated one.

Are you willing to work on this yourself?
No

@sokra
Copy link
Member

sokra commented Jun 11, 2019

In general old files should not be removed from the output directory since existing users could leave browser tabs open and request old files even after an update is deployed.

In development it's recommended to not use any hashing, since this will also slow down builds.

@abriginets
Copy link
Author

@sokra thanks. I have splitted my webpack config in two files for development and production builds and I'll build [hash]ed files in production builds only.

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

2 participants