【问题标题】:Npm multiple file script (lessc)Npm 多文件脚本 (lessc)
【发布时间】:2016-01-19 10:34:42
【问题描述】:

我正在尝试在我的package.json 中运行lessc PowerShell 命令行。 所以在我的脚本部分我有类似的东西:

Get-ChildItem *.less -Recurse | ForEach-Object {lessc $_.FullName > $_.BaseName.css}

但它给了我以下错误:

'Get-ChildItem' 未被识别为内部或外部命令

虽然这在 PowerShell 中正常执行

Get-ChildItem *.less -Recurse | ForEach-Object {echo $_.Name}

一个普通的lessc 命令也可以按预期工作。

有什么想法吗?

Also check this question that have another solution for this.

【问题讨论】:

    标签: css node.js powershell less


    【解决方案1】:

    错误消息表明您没有在 PowerShell 中运行该语句。 lessc 是一个 node.js 应用程序,而不是 PowerShell 命令,因此它在单独使用时可以正常工作也就不足为奇了。

    为了能够使用 PowerShell cmdlet,您需要在 PowerShell 中运行语句,例如像这样:

    powershell.exe -ExecutionPolicy Bypass -Command "Get-ChildItem  *.less -recurse | Foreach-Object{ lessc $_.FullName > $_.BaseName.css }"
    

    【讨论】:

    • 在 Foreach 命令之前还需要一个 powershell.exe -ExecutionPolicy Bypass -Command。谢谢
    • @ArgiropoulosStavros 否。您在单个 powershell.exe 进程中运行整个语句。如果您需要第二个,您很可能会遇到引号或未转义字符的问题。为了进一步排除故障,您需要显示 package.json 的实际内容,而不仅仅是您尝试运行的命令。
    猜你喜欢
    • 2012-06-10
    • 2013-08-12
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多