ksh*_*fbd 22 javascript typescript gulp angular
我正在关注Angular 2快速入门教程.以下是我的文件夹结构 -
??? gulpfile.js
??? index.html
??? js
| ??? app.component.js
| ??? boot.js
??? source
| ??? app.component.ts
| ??? boot.ts
??? node_modules
??? module 1
??? module 2
Run Code Online (Sandbox Code Playgroud)
我的打字稿文件在source/
目录中.我正在编译它到js/
目录.我正在使用gulp-typescript.
问题是,当我举个例子,重命名文件boot.ts
到bootstrap.ts
和重新编译,相应的bootstrap.js
文件被创建,但旧的boot.js
文件仍然保留在js /目录.
现在文件夹结构如下所示 -
??? gulpfile.js
??? index.html
??? js
| ??? app.component.js
| ??? bootstrap.js
| ??? boot.js
??? source
| ??? app.component.ts
| ??? bootstrap.ts
??? node_modules
??? module 1
??? module 2
Run Code Online (Sandbox Code Playgroud)
我想boot.js
通过gulp任务自动删除这个.怎么做到这一点?
Aka*_*ose 27
我来到这里看到了标题,并在混合物中添加一大堆不是解决方案.所以这就是我如何解决它.
用你的npm构建脚本作为前缀 rm -rf js &&
"scripts": {
...
"build": "rm -rf js/ && tsc",
...
},
Run Code Online (Sandbox Code Playgroud)
希望有人会觉得这很有用.
按照评论中的建议进行编辑
作为一种更通用的解决方案,请使用rm -rf js &&
而不是rm -rf js &&
.
rm -rf js &&
是一个npm模块,旨在跨平台(包括Windows)工作.要使其工作,首先将其安装为dev依赖项.
这个解决方案的灵感来自@Akash Kurian Jose's answer。由于他的解决方案取决于您使用的操作系统,我添加了这个适用于任何操作系统的解决方案:
将rimraf添加为开发依赖项:
"devDependencies": {
"rimraf": "^3.0.1"
}
Run Code Online (Sandbox Code Playgroud)
然后将这 3 个脚本添加到您的 package.json 中:
"rimraf": "./node_modules/rimraf/bin.js",
"clean" : "rimraf js/",
"compile": "npm run clean && tsc -p ./"
Run Code Online (Sandbox Code Playgroud)
当执行npm run compile
该js/
文件夹将在编译之前进行清洗。
安装gulp del.
$ npm install --save-dev gulp del
Run Code Online (Sandbox Code Playgroud)
创建任务.
var gulp = require('gulp');
var del = require('del');
gulp.task('clean:output', function () {
return del([
'js/'
]);
});
gulp.task('default', ['clean:output']);
Run Code Online (Sandbox Code Playgroud)
该解决方案是GabrielBB解决方案的改进。
安装 rimraf
npm i rimraf -D
添加以下 npm 脚本
"clean": "rimraf js/",
"prebuild": "npm run clean",
"build": "tsc",
Run Code Online (Sandbox Code Playgroud)
这利用了 npms 自动Pre 脚本
使用最新的tsc,您可以使用以下命令进行清理
tsc --build --clean
Run Code Online (Sandbox Code Playgroud)
我的TSC版本供您参考
$ tsc --version
Version 3.5.3
Run Code Online (Sandbox Code Playgroud)
请注意,-clean标志是项目引用的一部分,并且仅与它一起使用。
归档时间: |
|
查看次数: |
18603 次 |
最近记录: |