Skip to content

Commit

Permalink
fix: add required minimizer setting to the generated Nest rspack conf… (
Browse files Browse the repository at this point in the history
#28629)

## Current Behavior
When using Nest.js in combination with [decorator
metadata](https://docs.nestjs.com/fundamentals/execution-context#reflection-and-metadata),
the class names and handlers become mangled/compressed causing them to
lose the reference to the correct class/handler name.

## Expected Behavior
The decorator metadata works as intended.

## Approach
This PR implements a custom instance of the
`SwcJsMinimizerRspackPlugin`, where the setting is modified to keep
original class and function names from the `compress` and `mangle`
options.

## Related
I've opened a related PR on the rspack-examples repository:
rspack-contrib/rspack-examples#158
  • Loading branch information
lorenzodejong authored and jaysoo committed Oct 31, 2024
1 parent c0b7aef commit 2fd5b4c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/rspack/src/utils/generator-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,28 @@ function createConfig(
} else if (options.framework === 'nest') {
return `
const { composePlugins, withNx } = require('@nx/rspack');
const rspack = require('@rspack/core');
module.exports = composePlugins(withNx(), (config) => {
config.optimization = {
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
// We need to disable mangling and compression for class names and function names for Nest.js to work properly
// The execution context class returns a reference to the class/handler function, which is for example used for applying metadata using decorators
// https://docs.nestjs.com/fundamentals/execution-context#executioncontext-class
compress: {
keep_classnames: true,
keep_fnames: true,
},
mangle: {
keep_classnames: true,
keep_fnames: true,
},
},
}),
],
};
return config;
});
`;
Expand Down

0 comments on commit 2fd5b4c

Please sign in to comment.