Last active
October 1, 2015 16:48
-
-
Save plwalters/f7fc14615e57aa4961b9 to your computer and use it in GitHub Desktop.
Bundling framework files only
This file contains 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 runSequence = require('run-sequence'); | |
var changed = require('gulp-changed'); | |
var plumber = require('gulp-plumber'); | |
var to5 = require('gulp-babel'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var paths = require('../paths'); | |
var compilerOptions = require('../babel-options'); | |
var assign = Object.assign || require('object.assign'); | |
// transpiles changed es6 files to SystemJS format | |
// the plumber() call prevents 'pipe breaking' caused | |
// by errors from other gulp plugins | |
// https://www.npmjs.com/package/gulp-plumber | |
gulp.task('build-system', function () { | |
return gulp.src(paths.source) | |
.pipe(plumber()) | |
.pipe(changed(paths.output, {extension: '.js'})) | |
.pipe(sourcemaps.init({loadMaps: true})) | |
.pipe(to5(assign({}, compilerOptions, {modules:'system'}))) | |
.pipe(sourcemaps.write({includeContent: false, sourceRoot: paths.sourceMapRelativePath })) | |
.pipe(gulp.dest(paths.output)); | |
}); | |
// copies changed html files to the output directory | |
gulp.task('build-html', function () { | |
return gulp.src(paths.html) | |
.pipe(changed(paths.output, {extension: '.html'})) | |
.pipe(gulp.dest(paths.output)); | |
}); | |
// this task calls the clean task (located | |
// in ./clean.js), then runs the build-system | |
// and build-html tasks in parallel | |
// https://www.npmjs.com/package/gulp-run-sequence | |
gulp.task('build', function(callback) { | |
return runSequence( | |
'clean', | |
['build-system', 'build-html', 'bundle'], | |
callback | |
); | |
}); |
This file contains 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 jspm = require('jspm/api'); | |
var paths = require('../paths'); | |
var fs = require('fs'); | |
var bundleIt = function () { | |
return jspm.bundle( | |
[ | |
// '*', | |
'aurelia-bootstrapper', | |
'aurelia-http-client', | |
'aurelia-dependency-injection', | |
'aurelia-router', | |
'github:aurelia/[email protected]', | |
'github:aurelia/[email protected]', | |
'github:aurelia/[email protected]', | |
'github:aurelia/[email protected]', | |
'github:aurelia/[email protected]' | |
].join(' + '), | |
'app-bundle.js', | |
{inject:true, minify: true} | |
) | |
}; | |
gulp.task('bundle', function (done) { | |
bundleIt().then(function () { | |
fs.rename('app-bundle.js', 'dist/app-bundle.js', done); | |
}); | |
}); | |
gulp.task('copy-bundle', function (done) { | |
if (fs.existsSync('app-bundle.js')) { | |
fs.rename('app-bundle.js', 'dist/app-bundle.js', done); | |
} else { | |
bundleIt() | |
} | |
}); |
This file contains 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 paths = require('../paths'); | |
var browserSync = require('browser-sync'); | |
// outputs changes to files to the console | |
function reportChange(event){ | |
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); | |
} | |
// this task wil watch for changes | |
// to js, html, and css files and call the | |
// reportChange method. Also, by depending on the | |
// serve task, it will instantiate a browserSync session | |
gulp.task('watch', ['serve'], function() { | |
gulp.watch(paths.source, ['build-system', 'copy-bundle', browserSync.reload]).on('change', reportChange); | |
gulp.watch(paths.html, ['build-html', browserSync.reload]).on('change', reportChange); | |
gulp.watch(paths.style, browserSync.reload).on('change', reportChange); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment