图文并茂手把手教你How to copy files or directory in nodejs npm scripts编写脚本用npm或者node命令复制文件
2024-09-08 14:19:53
每天都要开心哦~~~
今天来个双语文档
先来说一下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.自定义拷贝案例
- 来看一些案例吧~discuss some examples
- 拷贝文件到某个目录Copy specific files into directory
- 假如你的js文件放在src/assets,你怎么只拷贝里面的JS文件到另一个目录呢?
- Suppose you have a javascript file in src/assets folder. How do you copy only javascript files to the output directory
"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
接下来说一下我们使用node命令执行脚本命令的方式
- 创建scripts\copy.js
- 编写代码
const copyfiles = require('copyfiles');
const copyEnd = () => {
console.log('我拷贝完啦~~~');
};
// 这个命令是针对根目录的哦
copyfiles(['dist/spa/assets/*.js', 'out'], { all: true }, copyEnd);
- 运行代码
node scripts/copy.js
- 今天就写到这里啦~小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~
- 大家要天天(▽)哦
欢迎大家指出文章需要改正之处~
学无止境,合作共赢
欢迎路过的小哥哥小姐姐们提出更好的意见哇~~
最新文章
- POJ 3669 Meteor Shower【BFS】
- web前端基础知识-(三)JavaScript基本操作
- IO复用三种方式
- 微信小程序-视图模板
- Websocket 协议解析
- jquery取消选择select下拉框
- 【转载】VC维的来龙去脉
- html5 video标签兼容性与自定义控件
- JSON和js对象之间的相互转化
- 被废弃的 Thread.stop, Thread.suspend, Thread.resume 和Runtime.runFinalizersOnExit
- JIRA 6.0.1 (ZIP Archive)最新破解方法,绝对可用
- Selenium来抓取动态加载的页面
- nodejs 教程
- css简单实现五角星评分、点赞收藏、展示评分(半颗星、1/3颗星)
- word中表格第一列序号的设置
- [APIO 2016]Gap
- cmd是命令提示符吗?
- javaWeb锁屏的简单实现
- LearnOpenGL学习笔记(一)——现有代码理解
- 兼容IE8及以上的常用css选择器