問題描述
我正在關注 Angular 2 快速入門 教程.以下是我的文件夾結構 -
I am following Angular 2 quick start tutorial. Following is my folder structure -
├── gulpfile.js
├── index.html
├── js
| ├── app.component.js
| └── boot.js
├── source
| ├── app.component.ts
| └── boot.ts
├── node_modules
├── module 1
└── module 2
我的打字稿文件位于 source/
目錄中.我正在將它編譯到 js/
目錄.我正在使用 gulp-typescript.
My typescript files are in source/
directory. I'm compiling it to js/
directory. I'm using gulp-typescript.
問題是當我例如將文件 boot.ts
重命名為 bootstrap.ts
并再次編譯時,對應的 bootstrap.js
文件已創建,但舊的 boot.js
文件仍保留在 js/目錄中.
The problem is when I, for example, rename the file boot.ts
to bootstrap.ts
and compile again, corresponding bootstrap.js
file is created but the old boot.js
file still remains in the js/ directory.
現在文件夾結構如下-
├── gulpfile.js
├── index.html
├── js
| ├── app.component.js
| └── bootstrap.js
| └── boot.js
├── source
| ├── app.component.ts
| └── bootstrap.ts
├── node_modules
├── module 1
└── module 2
我想通過 gulp 任務自動刪除這個 boot.js
.如何做到這一點?
I want to delete this boot.js
autonomically via gulp task. How to achieve this?
推薦答案
我來這里是看到標題,并且將 gulp 添加到組合中并不是解決方案.所以這就是我解決它的方法.
I came here seeing the title, and adding gulp into the mix was not a solution. So here is how I solved it.
在你的 npm 構建腳本前加上 rm -rf ./js/&&
Prefix your npm build script with rm -rf ./js/ &&
"scripts": {
...
"build": "rm -rf ./js/ && tsc",
...
},
rm -rf ./js/
forcefully 刪除 r./js/下面的所有文件和目錄 doku rm in bash
rm -rf ./js/
forcefully removes recursively all files and dirs below ./js/ doku rm in bash
&&
表示如果成功執行下一個命令 &&在 bash 中
&&
says if successfully do the next command && in bash
這篇關于如何從以前的 typescript(.ts) 文件中刪除已編譯的 JS 文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!