Skip to content

fix(bundling): webpack and rspack builds respect output.clean config option #30573

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 1 commit into from
Apr 2, 2025

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Apr 1, 2025

This PR fixes and issue where the standard output.clean option is ignored and replaced by the Nx-specific deleteOutputPath option on the NxAppWebpackPlugin and NxAppRspackPlugin plugins.

We want to allow users to use standards over our own features, so if we see that output.clean is set in webpack/rspack config, then we use that value.

For example, an Rspack config could be:

const { NxAppRspackPlugin } = require("@nx/rspack/app-plugin");
const { join } = require("path");

module.exports = {
  output: {
    path: join(__dirname, "dist/demo"),
    clean: false, // <-- THIS DOES NOT WORK!
  },
  plugins: [
    new NxAppRspackPlugin({
      // ...
    }),
  ],
};

But even though output.clean is false, each build will still delete dist. The only way to disable that behavior is to use the Nx-specific option like this:

const { NxAppRspackPlugin } = require("@nx/rspack/app-plugin");
const { join } = require("path");

module.exports = {
  output: {
    path: join(__dirname, "dist/demo"),
  },
  plugins: [
    new NxAppRspackPlugin({
      deleteOutputPath: false,
      // ...
    }),
  ],
};

Current Behavior

Setting output.clean in Webpack/Rspack config does nothing, and we always default our own deleteOutputPath to true.

Expected Behavior

Setting output.clean standard option is respected.

Related Issue(s)

Fixes #

@jaysoo jaysoo requested a review from a team as a code owner April 1, 2025 20:41
@jaysoo jaysoo requested a review from ndcunningham April 1, 2025 20:41
Copy link

vercel bot commented Apr 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Apr 2, 2025 0:33am

Copy link

nx-cloud bot commented Apr 1, 2025

View your CI Pipeline Execution ↗ for commit 61d0cda.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 33m 3s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 20s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check --base=75521... ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 1s View ↗
nx documentation ✅ Succeeded 1m 26s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-02 01:03:32 UTC

Copy link
Contributor

@ndcunningham ndcunningham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we deprecate this?

@jaysoo jaysoo force-pushed the fix/webpack-delete-output branch from 682a26e to 61d0cda Compare April 2, 2025 00:24
@jaysoo jaysoo merged commit 2d210b8 into master Apr 2, 2025
12 checks passed
@jaysoo jaysoo deleted the fix/webpack-delete-output branch April 2, 2025 01:16
jaysoo added a commit that referenced this pull request Apr 2, 2025
…option (#30573)

This PR fixes and issue where the standard `output.clean` option is
ignored and replaced by the Nx-specific `deleteOutputPath` option on the
`NxAppWebpackPlugin` and `NxAppRspackPlugin` plugins.

We want to allow users to use standards over our own features, so if we
see that `output.clean` is set in webpack/rspack config, then we use
that value.

For example, an Rspack config could be:

```js
const { NxAppRspackPlugin } = require("@nx/rspack/app-plugin");
const { join } = require("path");

module.exports = {
  output: {
    path: join(__dirname, "dist/demo"),
    clean: false, // <-- THIS DOES NOT WORK!
  },
  plugins: [
    new NxAppRspackPlugin({
      // ...
    }),
  ],
};
```

But even though `output.clean` is `false`, each build will still delete
`dist`. The only way to disable that behavior is to use the Nx-specific
option like this:

```js
const { NxAppRspackPlugin } = require("@nx/rspack/app-plugin");
const { join } = require("path");

module.exports = {
  output: {
    path: join(__dirname, "dist/demo"),
  },
  plugins: [
    new NxAppRspackPlugin({
      deleteOutputPath: false,
      // ...
    }),
  ],
};
```


## Current Behavior

Setting `output.clean` in Webpack/Rspack config does nothing, and we
always default our own `deleteOutputPath` to `true`.

## Expected Behavior
Setting `output.clean` standard option is respected.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
Copy link

github-actions bot commented Apr 8, 2025

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants