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

cleanupOutputBeforeBuild when watching file changes #158

Closed
timum-viw opened this issue Sep 12, 2017 · 6 comments
Closed

cleanupOutputBeforeBuild when watching file changes #158

timum-viw opened this issue Sep 12, 2017 · 6 comments

Comments

@timum-viw
Copy link

I'm not sure if this is wanted behaviour, but when using webpack --watch option the output folder apparently does not get cleared when recompiling after files change, even though I'm using cleanupOutputBeforeBuild. Normally the output files should get overwritten, but since I'm also using enableVersioning option I end up with a whole bunch of versioned files in my output folder.
Any thought about that?
Cheers

@Lyrkan
Copy link
Collaborator

Lyrkan commented Sep 12, 2017

Hi @timum-viw,

I would guess that's caused by the fact that the watch option of the clean-webpack-plugin isn't set to true when cleanOutputBeforeBuild is called.

There is a pending PR that'll allow to configure this plugin more easily (#152) but in the meantime you could try something like this:

// webpack.config.js
const Encore = require('@symfony/webpack-encore');
const CleanWebpackPlugin = require('clean-webpack-plugin');

Encore
  .setOutputPath('build/')
  .setPublicPath('/')
  .cleanupOutputBeforeBuild()
  // ...
;

const config = Encore.getWebpackConfig();

for (const plugin of config.plugins) {
  if ((plugin instanceof CleanWebpackPlugin) && plugin.options) {
    plugin.options.watch = true;
  }
}

module.exports = config;

@timum-viw
Copy link
Author

timum-viw commented Sep 12, 2017

sounds reasonable. the workaround seems to work for now.
Thanks!

@timum-viw timum-viw reopened this Sep 12, 2017
@timum-viw
Copy link
Author

ay, I was a bit quick on the last one. seems like not all files get rebuild. so now I'm missing the files that were unchanged..
Ideas?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Sep 12, 2017

@stof
Copy link
Member

stof commented Sep 12, 2017

Well, cleaning only invalidated files is quite hard to solve actually

@weaverryan
Copy link
Member

So this is not something we can fix. If clean-webpack-plugin fixes it someday, awesome! So, I'm closing for now!

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

4 participants