【问题标题】:how can I render pug(jade) to html in npm scripts?如何在 npm 脚本中将 pug(jade) 渲染为 html?
【发布时间】:2016-08-08 18:32:24
【问题描述】:

我正在尝试构建我的 package.json 文件,但在编写脚本时遇到了困难。

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1", 
"build-css":"node-sass --output-style compressed -o build/styles src/styles", 
"pugtohtml": "npm pug -D index.pug"  
},

这不起作用

我已经安装了 pug 包,现在我想只使用 npm 自动执行任务,你能帮我解决这个问题吗?如果你能给我一些关于如何学习编写脚本和使用自动化任务的提示和资源,我将不胜感激只需 npm,谢谢!

【问题讨论】:

  • 会不会只是pug -D index.pug 而不是npm pug -D index.pug
  • 你不必在 npm 中调用 npm,只需 pug [args]

标签: javascript node.js npm pug


【解决方案1】:

你必须这样写任务

"pugtohtml": "pug --output-style compressed -o dist/html/ assets/pug/*.pug"

【讨论】:

  • 它对我有用,但是我需要安装“npm”和“npm-cli”。记住这一点很好! XD!
  • 要在不全局安装的情况下运行它,可以从 node_modules 引用 pug。 "pugtohtml":"./node_modules/.bin/pug -P -o public/ Views/index.pug"
  • npx 可用于从本地安装的 deps 运行它,避免全局。
【解决方案2】:

看起来需要命令行客户端才能将其与 NPM 脚本一起使用。

根据Pug NPM page

npm install pug

命令行

安装最新版本的 Node.js 后,安装:

npm install pug-cli -g


我使用 npm install pug-cli --save-dev 代替,因为我更喜欢将包安装到我正在处理的项目的本地,但 YMMV。

如果您喜欢全局 (-g),您可能不需要 pug-cli 包来处理命令行,您可以使用此处提到的其他解决方案。

【讨论】:

    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多