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

Prevent CleanWebpackPlugin webpack plugin from deleting webpack assets #35986

Merged
merged 2 commits into from
Nov 19, 2021

Conversation

kasparsd
Copy link
Contributor

@kasparsd kasparsd commented Oct 27, 2021

Description

Fixes #35980.

How has this been tested?

The updated WP webpack configuration prevents the webpack assets from being deleted in the demo repository according to these GitHub action results.

Screenshots

patch-demo

Types of changes

  • Bug fix: prevent the webpack build process from deleting webpack assets from different configurations that are part of the same build task.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@gziolo gziolo requested a review from ocean90 October 27, 2021 10:13
@gziolo gziolo added [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended labels Oct 27, 2021
@gziolo
Copy link
Member

gziolo commented Nov 2, 2021

In johnagan/clean-webpack-plugin#122 they recommend using different output folders for individual configs to mitigate the issue.

Doesn't setting cleanStaleWebpackAssets set to false makes the usage of CleanWebpackPlugin obsolete? Would there be still a use case when the old build files get removed before running the build?

@kasparsd
Copy link
Contributor Author

kasparsd commented Nov 2, 2021

@gziolo In the example repo I'm already using different output folders for of each webpack config:

const configModern = {
    ...defaultConfig,
    entry: {
        modern: path.join( __dirname, 'js/src/modern.js' ),
    },
    output: {
        path: path.join( __dirname, 'js/dist/modern' ),
    },
};

const configLegacy = {
    ...defaultConfig,
    entry: {
        legacy: path.join( __dirname, 'js/src/legacy.js' ),
    },
    output: {
        path: path.join( __dirname, 'js/dist/legacy' ),
    },
}

The issue is caused by the cleanStaleWebpackAssets implementation which is enabled by default as it assumes that all previous builds (even for different configs) are stale assets and need to be removed.

Doesn't setting cleanStaleWebpackAssets set to false makes the usage of CleanWebpackPlugin obsolete?

My understanding is that cleanOnceBeforeBuildPatterns is the behaviour we want and removing cleanStaleWebpackAssets doesn't impact that.

@gziolo
Copy link
Member

gziolo commented Nov 8, 2021

I took it for a spin and it works correctly. Let's land this change after rebase. GitHub reports some merge conflicts that need to be resolved manually.

@gziolo
Copy link
Member

gziolo commented Nov 18, 2021

@kasparsd, can you rebase this PR so we could land it?

@kasparsd kasparsd force-pushed the fix/clean-webpack-plugin branch from c67e988 to 558fa01 Compare November 18, 2021 20:18
@kasparsd
Copy link
Contributor Author

@gziolo Thanks for the ping! Please let me know if this looks good now.

@gziolo gziolo merged commit bcaec31 into WordPress:trunk Nov 19, 2021
@github-actions github-actions bot added this to the Gutenberg 12.1 milestone Nov 19, 2021
@kasparsd kasparsd deleted the fix/clean-webpack-plugin branch December 2, 2021 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CleanWebpackPlugin in wp-scripts removes built files from previous webpack runs
2 participants