ng-cli-pug-loader icon indicating copy to clipboard operation
ng-cli-pug-loader copied to clipboard

Angular's index gives plain text instead of pug output.

Open Kompwu opened this issue 5 years ago • 12 comments

Very weird, here are my fields in angular.json:

"options": {
            "outputPath": "dist/angularSeed",
            "index": "src/index.pug",
            "main": "src/main.ts",

Did I make a mistake?

Kompwu avatar Jul 20 '18 10:07 Kompwu

I don't understand the problem 🤔 index.pug is not being parsed into HTML?

danguilherme avatar Jul 25 '18 18:07 danguilherme

@danguilherme Well... you're smart.

Kompwu avatar Nov 04 '18 01:11 Kompwu

Please help me to understand the issue or I'll have to close it.

danguilherme avatar Nov 05 '18 00:11 danguilherme

@danguilherme Angular's index gives plain text instead of pug output.

Kompwu avatar Nov 05 '18 00:11 Kompwu

@danguilherme I am having this issue as well. When you rewrite the index file as pug, it simply gets rendered as text.

chumaumenze avatar Nov 06 '18 03:11 chumaumenze

@chumaumenze oh, thanks, now I get it. I don't have the environment ready to test this, but will take a look as soon as possible.

While it isn't fixed, I recommend using plain old HTML for the index file, if that's an option.

danguilherme avatar Nov 06 '18 08:11 danguilherme

I have the same issue :-(

ibqn avatar Nov 19 '18 16:11 ibqn

@ibqn Any fix??

Kompwu avatar Nov 20 '18 01:11 Kompwu

@Kompwu nope, I simply have stopped using it...

ibqn avatar Nov 28 '18 20:11 ibqn

For me, this patch fixes the issue in Angular 8.1.1:

--- node_modules/@angular-devkit/build-angular/src/angular-cli-files/utilities/index-file/write-index-html.js
+++ node_modules/@angular-devkit/build-angular/src/angular-cli-files/utilities/index-file/write-index-html.js
@@ -13,8 +13,12 @@ const operators_1 = require("rxjs/operators");
 const package_chunk_sort_1 = require("../package-chunk-sort");
 const strip_bom_1 = require("../strip-bom");
 const augment_index_html_1 = require("./augment-index-html");
+const pug = require("pug");
 function writeIndexHtml({ host, outputPath, indexPath, files = [], noModuleFiles = [], moduleFiles = [], baseHref, deployUrl, sri = false, scripts = [], styles = [], postTransform, crossOrigin, }) {
-    return host.read(indexPath).pipe(operators_1.map(content => strip_bom_1.stripBom(core_1.virtualFs.fileBufferToString(content))), operators_1.switchMap(content => augment_index_html_1.augmentIndexHtml({
+    const pugMap = /\.pug$/.test(indexPath)
+        ? operators_1.map(content => pug.render(content))
+        : operators_1.map(x => x);
+    return host.read(indexPath).pipe(operators_1.map(content => strip_bom_1.stripBom(core_1.virtualFs.fileBufferToString(content))), pugMap, operators_1.switchMap(content => augment_index_html_1.augmentIndexHtml({
         input: core_1.getSystemPath(outputPath),
         inputContent: content,
         baseHref,
@@ -31,7 +35,7 @@ function writeIndexHtml({ host, outputPath, indexPath, files = [], noModuleFiles
                 .pipe(operators_1.map(data => core_1.virtualFs.fileBufferToString(data)))
                 .toPromise();
         },
-    })), operators_1.switchMap(content => (postTransform ? postTransform(content) : rxjs_1.of(content))), operators_1.map(content => core_1.virtualFs.stringToFileBuffer(content)), operators_1.switchMap(content => host.write(core_1.join(outputPath, core_1.basename(indexPath)), content)));
+    })), operators_1.switchMap(content => (postTransform ? postTransform(content) : rxjs_1.of(content))), operators_1.map(content => core_1.virtualFs.stringToFileBuffer(content)), operators_1.switchMap(content => host.write(core_1.join(outputPath, core_1.basename(indexPath.replace(/\.pug$/, '.html'))), content)));
 }
 exports.writeIndexHtml = writeIndexHtml;
 function filterAndMapBuildFiles(files, extensionFilter) {
--- node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin.js
+++ node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin.js
@@ -11,6 +11,7 @@
 const webpack_sources_1 = require("webpack-sources");
 const augment_index_html_1 = require("../utilities/index-file/augment-index-html");
 const strip_bom_1 = require("../utilities/strip-bom");
+const pug = require("pug");
 function readFile(filename, compilation) {
     return new Promise((resolve, reject) => {
         compilation.inputFileSystem.readFile(filename, (err, data) => {
@@ -37,7 +38,8 @@
     apply(compiler) {
         compiler.hooks.emit.tapPromise('index-html-webpack-plugin', async (compilation) => {
             // Get input html file
-            const inputContent = await readFile(this._options.input, compilation);
+            let inputContent = await readFile(this._options.input, compilation);
+            inputContent = /\.pug$/.test(this._options.input) ? pug.render(inputContent) : inputContent;
             compilation.fileDependencies.add(this._options.input);
             // Get all files for selected entrypoints
             const files = [];

kmvi avatar Jul 13 '19 04:07 kmvi

Hello, I Have the same problem, Steps to reproduce the problem: ng new ng add ng-cli-pug-loader in angular.json: "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/Folderproject", "index": "src/index.pug",

and it will just break on ng serve everything that is inside the index.pug doctype 5 html head meta(charset="utf-8") base(href="/") title MyTitle body h1 {{ title }} app-root h2 Hello Just renders raw inside the prerendered angular file. Attached screenshot of google chrome GithubErrorPug Thanks for the good tools you develops.

RamiroCampa avatar Dec 11 '19 00:12 RamiroCampa

Some update on this issue ?

pedrohms avatar Apr 13 '21 21:04 pedrohms

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

danguilherme avatar Nov 22 '23 00:11 danguilherme