在Angular CLI构建脚本中重命名文件

时间:2017-08-02 20:45:32

标签: angular-cli npm-scripts

假设我需要在index.html过程中将abc.xyz重命名为ng build,这可能吗?如果是这样,我该怎么做呢?

我假设我必须修改package.json build脚本,并且可能使用管道,但我无法通过查看Angular CLI github或通过NPM的网站。谷歌也没有帮助过我......我一定不能问正确的问题。

1 个答案:

答案 0 :(得分:2)

CLI中没有类似的东西你可以重命名文件,但是你可以通过使用自定义的npm脚本来做到这一点。如何做到这一点有多种选择:

  • 如果您在Windows,则可以在您的npm move中使用build script cmd命令:

    "build": "ng build && move dist\\index.html dist\\abc.xyz"
    
  • 如果您在Linux,则必须使用mv代替:

    "build": "ng build && mv dist/index.html dist/abc.xyz"
    

然后通过运行npm run build,您将获得所需的结果。

如果需要,您也可以使用cash-mv npm包,这样build script就会cross platform(Linux版本的脚本对所有平台都有效)。< / p>