ioionic
ioionic

Reputation: 1

ionic typescript installation ubuntu

I installed ionic and cordova. I created the ionic project

ionic start myapp blank

I added gulp-tsc on my project

npm install gulp-tsc

I edited gulpfile.js at the root of the ionic project :

var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var typescript = require('gulp-tsc');

var paths = {
  sass: ['./scss/**/*.scss']
  typescript: ['./www/scripts/**/*.ts']
};

gulp.task('default', ['sass', 'compile']);

function compileTypeScript(done) {
	gulp.src(paths.typescript)
	.pipe(typescript({ sourcemap: true, out: 'tslib.js', sourceRoot: '../scripts' }))
	.pipe(gulp.dest('./www/js/'))
	.on('end', done);
}

gulp.task('compile', compileTypeScript);

gulp.task('sass', function(done) {
  gulp.src('./scss/ionic.app.scss')
    .pipe(sass({
      errLogToConsole: true
    }))
    .pipe(gulp.dest('./www/css/'))
    .pipe(minifyCss({
      keepSpecialComments: 0
    }))
    .pipe(rename({ extname: '.min.css' }))
    .pipe(gulp.dest('./www/css/'))
    .on('end', done);
});

gulp.task('watch', function() {
  compileTypeScript();
  gulp.watch(paths.sass, ['sass']);
  gulp.watch(paths.typescript, ['compile']);
});

gulp.task('install', ['git-check'], function() {
  return bower.commands.install()
    .on('log', function(data) {
      gutil.log('bower', gutil.colors.cyan(data.id), data.message);
    });
});

gulp.task('git-check', function(done) {
  if (!sh.which('git')) {
    console.log(
      '  ' + gutil.colors.red('Git is not installed.'),
      '\n  Git, the version control system, is required to download Ionic.',
      '\n  Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
      '\n  Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
    );
    process.exit(1);
  }
  done();
});

I added a simple ts file on www/scripts folder (a class), and when I run ionic serve, tslib.js is not generated. I don't have any error. What I missed to do to generate the js file from ts files ?

Thanks.

Upvotes: 0

Views: 116

Answers (2)

Deepak Kumar
Deepak Kumar

Reputation: 114

Some times the dependency does not install in the same, what happens, when you install ionic then typescript automatically install as a dependency, I suggest you run this command to install manually typescript dependency.

sudo npm install -g typescript

Upvotes: 0

user5840004
user5840004

Reputation:

You may try this example:https://github.com/anchann/angularjs-typescript-e2e.

You have to have a separate grunt task running that watches your .ts files and compiles them into the tslib.js.

Upvotes: 1

Related Questions