nx icon indicating copy to clipboard operation
nx copied to clipboard

Support running nest with swc

Open mcmxcdev opened this issue 2 years ago • 1 comments
trafficstars

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

mcmxcdev avatar Jun 26 '23 15:06 mcmxcdev

Any update? Would love to use it 👀

DobroslavR avatar Jul 04 '23 07:07 DobroslavR

Any updates? I try use direct commands in project.json but no profit

zimiovid avatar Jul 25 '23 07:07 zimiovid

Any updates?

Andr-07 avatar Jul 25 '23 07:07 Andr-07

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.

ilesar avatar Jul 30 '23 21:07 ilesar

Probably related to: https://github.com/nrwl/nx/issues/8900

jacqueslareau avatar Aug 16 '23 13:08 jacqueslareau

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;
  }
);

lstanden avatar Jan 04 '24 06:01 lstanden

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.

timonmasberg avatar Jan 04 '24 12:01 timonmasberg

Any updates?.. In my case I've tried few different ways yet still can't run nest with swc under nx.

santhitak avatar Jan 07 '24 07:01 santhitak

I would like to having this too 🙏🏻

gperdomor avatar Apr 18 '24 13:04 gperdomor

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!

ndcunningham avatar Jun 07 '24 21:06 ndcunningham

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.

github-actions[bot] avatar Jul 08 '24 00:07 github-actions[bot]