Skip to content
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

Support running nest with swc #17791

Closed
mcmxcdev opened this issue Jun 26, 2023 · 11 comments
Closed

Support running nest with swc #17791

mcmxcdev opened this issue Jun 26, 2023 · 11 comments
Assignees
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx type: feature

Comments

@mcmxcdev
Copy link

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

@leosvelperez leosvelperez added the scope: node Issues related to Node, Express, NestJS support for Nx label Jun 26, 2023
@DobroslavR
Copy link

Any update? Would love to use it 👀

@zimiovid
Copy link

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

@Andr-07
Copy link

Andr-07 commented Jul 25, 2023

Any updates?

@ilesar
Copy link

ilesar commented Jul 30, 2023

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.

@jacqueslareau
Copy link

Probably related to: #8900

@lstanden
Copy link

lstanden commented Jan 4, 2024

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

@timonmasberg
Copy link

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.

@santhitak
Copy link

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

@gperdomor
Copy link
Contributor

I would like to having this too 🙏🏻

@ndcunningham
Copy link
Contributor

ndcunningham commented Jun 7, 2024

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!

Copy link

github-actions bot commented Jul 8, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Jul 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx type: feature
Projects
None yet
Development

No branches or pull requests