Skip to content

Not able to pass swc options and generate sourceMaps #3

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

Open
Crismon96 opened this issue Apr 9, 2024 · 0 comments
Open

Not able to pass swc options and generate sourceMaps #3

Crismon96 opened this issue Apr 9, 2024 · 0 comments

Comments

@Crismon96
Copy link

Thanks for creating this configuration so that we can have more performant nest applications.
I want to generate sourceMaps for my bundle to find bugs more easily. Unfortunately I am not able to configure swc in your setup, swcOptions can not be configured by the exported functions.

I then copied your implementation for a production build and adjusted only the sourceMap parameter.
Unfortunately the output does not include any source map files whatsoever. I am not the most experienced in terms of this build tooling so maybe you can help me find the issue.

This is my configuration (a copy of your production config only that it should pass sourceMaps: true as an options to swc):

const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');

const swcConfig = {
  sourceMaps: true,
  module: {
    type: 'commonjs',
    strict: true,
  },
  jsc: {
    target: 'es2020',
    parser: {
      syntax: 'typescript',
      decorators: true,
    },
    transform: {
      legacyDecorator: true,
      decoratorMetadata: true,
    },
    keepClassNames: true,
  },
};

const baseConfig = {
  externals: [
    // HINT: We need to include this package inside the build to handle missing dependencies errors, and tree-shake it
    nodeExternals({
      modulesFromFile: true,
      allowlist: ['webpack/hot/poll?100', '@rnw-community/nestjs-webpack-swc'],
    }),
  ],
  externalsPresets: { node: true },
  cache: {
    type: 'filesystem',
    cacheDirectory: path.resolve(process.cwd(), '.build_cache'),
    allowCollectingMemory: true,
  },
  module: {
    rules: [
      {
        test: /\.ts?$/u,
        use: { loader: 'swc-loader', options: { ...swcConfig, minify: false, sourceMaps: true } },
        exclude: /(node_modules)/u,
      },
    ],
  },
  node: {
    __dirname: false,
    __filename: false,
  },

  mode: 'production',
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        parallel: true,
        terserOptions: {
          keep_classnames: true,
          mangle: false,
        },
      }),
    ],
  },
};

// Add CopyPlugin to the plugins array
baseConfig.plugins = [
  ...(baseConfig.plugins || []), // Spread existing plugins
  new CopyPlugin({
    patterns: [
      { from: 'templates/**/*.xlsx', to: '[path][name][ext]' },
      { from: '../../libs/i18n/backend/src/locales', to: 'locales' },
    ],
  }),
];

// Export the modified configuration
module.exports = baseConfig;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant