Jack Hsu 2d210b8d0e
fix(bundling): webpack and rspack builds respect output.clean config 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 #
2025-04-01 21:16:05 -04:00
..
2024-09-18 10:25:28 +01:00
2024-09-18 10:25:28 +01:00
2024-09-18 10:25:28 +01:00