K
K
Konstantin2020-01-12 15:00:59
Angular
Konstantin, 2020-01-12 15:00:59

How to build an Angular library with a separate Webpack.config?

I created the Angular library inside the workspace itself.
How to tell angular that it needs to be built not through angular.json but through its own webpack.config?
Now the angular.json configurator is like this:

"test-lib": {
      "projectType": "library",
      "root": "projects/test-lib",
      "sourceRoot": "projects/test-lib/src",
      "prefix": "tl",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-ng-packagr:build",
          "options": {
            "tsConfig": "projects/test-lib/tsconfig.lib.json",
            "project": "projects/test-lib/ng-package.json"
          }
        }
}

And my custom webpack is:
var path = require("path");
var webpack = require("webpack");

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        include: path.join(__dirname, './projects/src/lib'),
        use: [
          'style-loader',
          {
            loader: 'typings-for-css-modules-loader',
            options: {
              modules: true,
              namedExport: true
            }
          }
        ]
      },
        {
            test: /\.scss$/,
            exclude: /node_modules/,
            use: [
                "style-loader",
                {
                    loader: "typings-for-css-modules-loader",
                    options: {
                        modules: true,
                        namedExport: true,
                        silent: true,
                        localIdentName: production ? "r_[hash:base64:5]" : "[local]___[hash:base64:5]"
                    }
                },
                { loader: "sass-loader" }
            ]
        }
    ]
},

  plugins: [
    new webpack.DefinePlugin({
      'STABLE_FEATURE': JSON.stringify(true),
      'EXPERIMENTAL_FEATURE': JSON.stringify(false)
    })
  ]
};

The library is built by the command: ng build test-lib

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question