【问题标题】:Set pug includes to not compile设置哈巴狗包含不编译
【发布时间】:2019-12-13 14:39:59
【问题描述】:

我正在使用

运行 pug CLI

pug src --out web --watch

如果我有

src/
   index.pug 
   includes/
      scripts.pug
web/
  index.html (generated)

在 index.pug 中:include includes/scripts.pug

如果我修改 scripts.pug,使用此设置,它会生成我不需要的 web/includes/scripts.html,我不想为了保持干净。

有没有办法避免某些文件/目录编译? (目前一种解决方法是将包含在 html 形式中,但也许有办法)

【问题讨论】:

    标签: directory pug-loader


    【解决方案1】:

    在文件中添加下划线前缀应该告诉 Pug 不要直接编译它们。这对于仅用作包含文件的文件非常有用。

    所以你应该将scripts.pug 重命名为_scripts.pug

    src/
      index.pug 
      includes/
        _scripts.pug
    web/
      index.html (generated)
    

    然后将index.pug 中的include 语句重写为:include includes/_scripts.pug

    【讨论】:

    • 你确定吗?我接受了答案,但直到现在才进行测试,它似乎不起作用。据我所见,必须安装一个特定的 pug-cli2。
    • 它适用于gulp-pug 包,但对于其他工具可能会有所不同。
    【解决方案2】:

    pug-cli 不知道不编译某些文件。就像前面提到的答案一样,它确实适用于 gulp-pug 但不适用于 pug-cli。我能想到的不编译包含或扩展文件的唯一方法是将这些文件放在单独的根目录中。例如:

    src/
      templates/
            views/
                index.pug
            includes/
                scripts.pug
    web/
      index.html (generated)
    

    然后设置 pug 只编译views目录。

    pug -w src/templates/views/ -o web/ -P
    

    【讨论】:

      猜你喜欢
      • 2017-07-24
      • 2018-02-21
      • 2018-05-17
      • 2020-04-17
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多