danguilherme / ng-cli-pug-loader

:sparkles: Angular schematics to add .pug to your project
GNU General Public License v3.0
56 stars 17 forks source link

Double rules in webpack-configs/common.js #34

Closed alexprykhodko closed 10 months ago

alexprykhodko commented 4 years ago

The module.rules in node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js has the following lines after installing new npm packages with ng-cli-pug-loader installed:

rules: [ { test: /.(pug|jade)$/, exclude: /.(include|partial).(pug|jade)$/, use: [ { loader: "apply-loader" }, { loader: "pug-loader" } ] }, { test: /.(include|partial).(pug|jade)$/, loader: "pug-loader" }, { test: /\.(pug|jade)$/, exclude: /\.(include|partial)\.(pug|jade)$/, use: [ { loader: "apply-loader" }, { loader: "pug-loader" } ] }, { test: /\.(include|partial)\.(pug|jade)$/, loader: "pug-loader" },

The resulting double rules produce errors as seen in https://github.com/pugjs/pug-loader/issues/120

The issue is corrected by changing the rules to:

rules: [ { test: /\.(pug|jade)$/, exclude: /\.(include|partial)\.(pug|jade)$/, use: [ { loader: "apply-loader" }, { loader: "pug-loader" } ] }, { test: /\.(include|partial)\.(pug|jade)$/, loader: "pug-loader" },

(Note the correct escaping)

On the very first run of 'ng-add-pug-loader.js', the newly added rule in module.rules has bad escaping, which results in adding the new rule on the consecutive runs of 'ng-add-pug-loader.js':

{ test: /.(pug|jade)$/, exclude: /.(include|partial).(pug|jade)$/, use: [ { loader: "apply-loader" }, { loader: "pug-loader" } ] }, { test: /.(include|partial).(pug|jade)$/, loader: "pug-loader" }

Steps to reproduce:

  1. Run ng new my-app.
  2. Run ng add ng-cli-pug-loader.
  3. Rename 'app.component.html' to 'app.component.pug'.
  4. Run ng add @angular/material

Version info:

Angular CLI: 9.1.1 Node: 13.12.0

danguilherme commented 10 months ago

This project is no longer maintained. Check out ngx-pug-builders to add support to pug files to your Angular project.