通过npm脚本递归地跨平台复制文件 [英] Recursively copy files cross-platform via npm script

查看:82
本文介绍了通过npm脚本递归地跨平台复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 package.json 构建脚本中有一个复制命令(不能快速更改它).

We have within a package.json build script a copy command (no we cant quickly change that).

有没有什么解决方案可以使我们使用相同的语法轻松地在多平台上工作?

Is there any solution we can make this work multiplatform with the same syntax easily?

我查看了几个npm复制程序包,但它们不会从Windows转换为unix路径.

I looked in several npm copy packages, but they don't transpile from windows to unix paths.

我们基本上需要这样的东西:

We basically need something like:

"build": "doStuff && cp -r ../folder/ /dist/"

适用于Windows.

working for windows.

有什么想法吗?

推荐答案

对于跨平台解决方案,请考虑使用 shx 包.

For a cross-platform solution consider utilizing the shx package.

  1. 首先 cd 到您的项目目录,然后运行以下命令进行安装:

  1. Firstly cd to your project directory and run the following command to install it:

npm i -D shx

  • 然后在 package.json scripts 部分中重新定义您的 build 脚本,如下所示:

  • Then redefine your build script in the scripts section of your package.json as follows:

    "scripts": {
       "build": "doStuff && shx cp -r ../folder/ ./dist/"
    }
    

  • 这篇关于通过npm脚本递归地跨平台复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆