[Fixed] How to delete compiled JS files from previous typescript(.ts) files?

Issue

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

My typescript files are in source/ directory. I’m compiling it to js/ directory. I’m using gulp-typescript.

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.

Now the folder structure looks like following-

├── gulpfile.js
├── index.html
├── js
|   ├── app.component.js
|   └── bootstrap.js
|   └── boot.js
├── source
|   ├── app.component.ts
|   └── bootstrap.ts
├── node_modules
    ├── module 1
    └── module 2

I want to delete this boot.js autonomically via gulp task. How to achieve this?

Solution

Install gulp del.

$ npm install --save-dev gulp del

Create the task.

var gulp = require('gulp');
var del = require('del');

gulp.task('clean:output', function () {
  return del([
    'js/'
  ]);
});

gulp.task('default', ['clean:output']);

You can find more info on gulp del here.

Leave a Reply

(*) Required, Your email will not be published