nx
nx copied to clipboard
Support running nest with swc
Description
Nest v10 release introduced the possibility to run nest with swc See more: https://trilon.io/blog/nestjs-10-is-now-available#nestjs-%EF%B8%8F-swc
Motivation
Quicker development iterations than with tsc
Any update? Would love to use it 👀
Any updates? I try use direct commands in project.json but no profit
Any updates?
You can use this section in the docs to setup SWC. Unfortunately, you have to do it in every NestJS application.
Basically, you just have to paste this code in your webpack.config.js in every app.
const { composePlugins, withNx } = require('@nx/webpack');
const swcDefaultConfig =
require('@nestjs/cli/lib/compiler/defaults/swc-defaults').swcDefaultsFactory()
.swcOptions;
module.exports = composePlugins(withNx(), (config) => {
config.module.rules.push({
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: swcDefaultConfig,
},
});
return config;
});
Of course, make sure that you have the nestjs/cli installed locally in the project.
EDIT: With further inspection, I'm actually not seeing any speed improvements with this fix.
Probably related to: https://github.com/nrwl/nx/issues/8900
I think this does the trick:
const { composePlugins, withNx } = require('@nx/webpack');
// Nx plugins for webpack.
module.exports = composePlugins(
withNx({
target: 'node',
compiler: 'swc',
}),
(config) => {
// Update the webpack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
return config;
}
);
I think this does the trick:
const { composePlugins, withNx } = require('@nx/webpack'); // Nx plugins for webpack. module.exports = composePlugins( withNx({ target: 'node', compiler: 'swc', }), (config) => { // Update the webpack config as needed here. // e.g. `config.plugins.push(new MyPlugin())` return config; } );
For me, it is the same as the solution above, no speed improvement.
Any updates?.. In my case I've tried few different ways yet still can't run nest with swc under nx.
I would like to having this too 🙏🏻
Sorry for the late response.
This should already be supported. Enabling it should be to change the compiler options the webpack config via withNx({ compiler: 'swc' }) this should add the appropriate loader.
Reference: https://github.com/nrwl/nx/blob/fix/node-e2e-test/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts#L78
If this does not work for you please feel free to open a new issue with a small repo!
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.