用express art-template渲染出来的页面源码有空格

Author: chancmsCreated Aug 6, 2023Updated Dec 21, 2023

问题:用express art-template渲染出来的页面源码有空格,如下图

image

通过压缩等各种配置均不生效:

javascript
const htmlMinifier = require("html-minifier");
javascript
  //配置模板引擎
  app.set("view options", {
    debug: process.env.NODE_ENV !== "prd",
    cache: process.env.NODE_ENV == "prd",
    minimize: true,
   // HTML 压缩器。仅在 NodeJS 环境下有效
   htmlMinifier: htmlMinifier,

   // HTML 压缩器配置。参见 https://github.com/kangax/html-minifier
    htmlMinifierOptions: {
      collapseWhitespace: true,
      minifyCSS: true,
      minifyJS: true,
      includeAutoGeneratedTags: true,
        removeAttributeQuotes: true,
        removeComments: true,
        removeRedundantAttributes: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        sortClassName: true,
        useShortDoctype: true,
        collapseWhitespace: true,
      // 运行时自动合并:rules.map(rule => rule.test)
      ignoreCustomFragments: [],
    },
  });
  app.set("view engine", "html");
  app.set("views", setPath(appRoot, "view"));
  app.engine(".html", require("express-art-template"));