Last active
March 25, 2016 15:16
-
-
Save kmassada/cab16a07c28a09cbdc92 to your computer and use it in GitHub Desktop.
Ionic+Webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 tsd = require('gulp-tsd'); | |
var typescript = require('gulp-tsc'); | |
var jscs = require('gulp-jscs'); | |
var inject = require('gulp-inject'); | |
var webpack = require('webpack-stream'); | |
var bower = require('gulp-bower'); | |
var paths = { | |
sass: ['./scss/**/*.scss'], | |
src: ['./src/**/*.ts'], | |
build: ['./build/**/*.js'], | |
js: ['./www/js/**/*.js'], | |
}; | |
gulp.task('build', ['webpack'], function() { | |
var injectAngularSrc = gulp.src(paths.js, | |
{read: false}); | |
var injectAngularOptions = { | |
ignorePath: 'www/', | |
name: 'angular', | |
}; | |
return gulp.src('./www/*.html') | |
.pipe(inject(injectAngularSrc,injectAngularOptions)) | |
.pipe(gulp.dest('./www/')); | |
}); | |
gulp.task('webpack', ['bower','tsd', 'ts'], function() { | |
return gulp.src(paths.build) | |
.pipe(webpack({devtool: 'source-map', | |
output: { | |
filename: 'webpack.bundle.js', | |
}, | |
})) | |
.pipe(gulp.dest('./www/js')); | |
}); | |
gulp.task('jscs', function() { | |
return gulp.src(paths.js) | |
.pipe(jscs({fix: true})) | |
.pipe(gulp.dest('./www/js/')); | |
}); | |
g | |
gulp.task('tsd', function(callback) { | |
tsd({ | |
command: 'reinstall', | |
config: './tsd.json', | |
}, callback); | |
}); | |
gulp.task('ts', function() { | |
gulp.src(paths.src) | |
.pipe(typescript({ | |
emitError: false, | |
})) | |
.pipe(gulp.dest('build/')); | |
}); | |
gulp.task('bower', function() { | |
return bower(); | |
}); | |
gulp.task('default', ['sass', 'build']); | |
gulp.task('sass', function(done) { | |
gulp.src('./scss/ionic.app.scss') | |
.pipe(sass()) | |
.on('error', sass.logError) | |
.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() { | |
gulp.watch(paths.sass, ['sass']); | |
gulp.watch(paths.src, ['build']); | |
}); | |
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment