Skip to content

Angular CLI not allowing custom webpack loader to run on index.html #14392

@ashutoshmittal2309

Description

@ashutoshmittal2309

Command

- [ X] build
- [ X] serve

Is this a regression?

No. We are migrating from older versions to use Angular 7 cli project for first time

Description

We have written a custom webpack loader for our requirements which needs to be run on index.html file. To extend webpack configuration, we used below npm module -

https://github.com/meltedspark/angular-builders

We updated the angular.json file as per documentation of above module.

We were able to successfully use this module to extend webpack config but observed that our loader was run for all html files within project except index.html. Here is our custom webpack config that we used alongside the module -

const path = require('path');
module.exports = {
 module: {
    rules: [{
      test: /\.html/,
      use: [
          '<custom-loader>'
       ]
    }]
 }

While debugging, we found that index.html is handled separately using IndexHTMLWebpackPlugin by CLI which we assume might be the cause of this behavior.

Why we need custom loader?
We have a large website developed in a federated model and maintained by many teams across different geographic locations. To maintain consistency across all pages for Header/Footer content we have developed it separately as a Preact application. We use this Webpack loader to update index.html with HTML/JS/CSS of our application.

We are using Index.html to inject the code to keep Preact application out of Angular context.

@alan-agius4 I had discussed this with @mgechev during Angular conference last week and he suggested me to file a bug and reach out to you

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions