编程语言
首页 > 编程语言> > 图文并茂手把手教你How to copy files or directory in nodejs npm scripts编写脚本用npm或者node命令复制文件

图文并茂手把手教你How to copy files or directory in nodejs npm scripts编写脚本用npm或者node命令复制文件

作者:互联网

每天都要开心哦~~~

今天来个双语文档

先来说一下npm 执行的方式

1.首先,进入项目目录,下载依赖,添加到dev依赖

1.First, Go to your application project, Install copyfiles dependency with the below command Note: please add this as devDependencies using –save-dev

npm install --save-dev copyfiles

2.把下面代码放到你的package.json,就像下图那个样子

2.In the package.json file, There is a script tag, add below line of code

"scripts": {
    "copy": "copyfiles source destination"
}

3.最后,我们可以用npm run copy命令进行拷贝文件操作啦~~

3.Finally, You can script by calling npm run copy command in terminal

4.npm copyfiles examples

4.自定义拷贝案例

"copyjavascript": "copyfiles src/assets/*.js destination"
npx copyfiles dist test
npx copyfiles dist/spa/assets/*.js out
npx copyfiles dist/spa/* out
npx copyfiles dist/spa/* test
npx copyfiles dist/spa test  
npx copyfiles dist/spa test -a
npx copyfiles -a dist/spa test
npx copyfiles -a dist/spa/assets/* test

image.png

接下来说一下我们使用node命令执行脚本命令的方式

const copyfiles = require('copyfiles');

const copyEnd = () => {
  console.log('我拷贝完啦~~~');
};
// 这个命令是针对根目录的哦
copyfiles(['dist/spa/assets/*.js', 'out'], { all: true }, copyEnd);


node scripts/copy.js

欢迎大家指出文章需要改正之处~
学无止境,合作共赢

在这里插入图片描述

欢迎路过的小哥哥小姐姐们提出更好的意见哇~~

标签:npm,files,node,copyfiles,npx,spa,copy,dist
来源: https://www.cnblogs.com/sugartang/p/16468545.html