2

Background

@angular-builders/custom-webpack allows us to customize the webpack config of angular build, tutorial here. I am using it to build the additional scripts for web extension (Chrome/Firefox).

Here is the extra.webpack.config.js that I have included in angular.json

const { resolve } = require('path');

const scriptsDir = __dirname;

module.exports = {
  entry: {
    "background-script": resolve(scriptsDir, 'background-script/boot.ts'),
    "fill-manager": [resolve(scriptsDir, 'fill-manager/boot.ts')],
    "site-bridge": resolve(scriptsDir, 'site-bridge/boot.ts')
  }
};

As expected it outputs background-script.js, fill-manager.js and site-bridge.js alongside angular build artifacts. As this webpack config is merged with the angular's webpack config, we can control all the optimizations, hashing, source maps etc from a single angular.json file.

Problem

I also want to bundle additional css files that would be used with extension scripts and be controlled by angular build.

I might be able to add specific rules, loaders etc to extra.webpack.config.js but I do not want to deal with postcss, autoprefixer and sass loaders etc as its already being done inside angular.

Just like script files, simply adding css entry inside extra.webpack.config.js does not produce css file i.e.

module.exports = {
  entry: {
    ...
    "fill-manager": [resolve(scriptsDir, 'fill-manager/boot.ts'), resolve(scriptsDir, 'fill-manager/main.css')],
    ...
  }
};

Is there a way where I can specify a css/scss file entry in extra.webpack.config.js and it just output a bundled css file using configuration based on angular?

JJJ
  • 32,902
  • 20
  • 89
  • 102
bilal.haider
  • 318
  • 1
  • 4
  • 18
  • did you ever find a solution to that? I'm currently having the exact same issue and there isn't a lot of usefull information online... – Nannanas Feb 21 '23 at 19:50

0 Answers0