@nrwl/node:build: How to change output file name?

Viewed 1971

I am working in a nx monorepo with Angular CLI and a Node backend. In angular.json, I use a custom webpack config to change the filename of the bundle. Calling ng build app (which invokes @nrwl/node:build) works fine and bundles the file with the specified name.

The thing is: Calling ng serve app gives the error Cannot find module <path-to-outdir>/main.js. Looking at the code, it seems that the filename "main.js" is hardcoded!

How do I change the out filename in a way that @nrwl/node:execute is aware of that filename or is there any way to configure the build/execute to take a custom filename?

Thanks!

My angular.json looks like:

"service": {
  ...
  "architect": {
    "build": {
      "builder": "@nrwl/node:build",
      "options": {
        "webpackConfig": "apps/service/webpack.config.js",
        "outputPath": "dist/apps/service",
        "filename": "my-main-filename.js", // Note: webpack.config.ts reads this
        "main": "apps/service/src/my-main-filename.ts",
        ...
        }
    },
    "serve": {
          "builder": "@nrwl/node:execute",
          "options": {
            "buildTarget": "service:build"
          },
    }
...

And the webpack.config.js

module.exports = (config, context) => {
  // Extract output path from context
  const {
    options: { outputPath, filename },
  } = context;

  config.output = {
    filename: filename,
    path: outputPath
  }
  return config;
};

The version of @nrwl/node is 9.2.1

0 Answers
Related