Permalink
Browse files

feat(project): bundle into single file

BREAKING CHANGE: all imports need to use 'aurelia-api'
  • Loading branch information...
doktordirk committed Apr 3, 2016
1 parent bbbf189 commit b471d570b7b4b3a3e730d5e2ea420dc5d14134ce
Showing with 41 additions and 23 deletions.
  1. +40 −23 build/tasks/build.js
  2. +1 −0 package.json
@@ -14,7 +14,7 @@ var vinylPaths = require('vinyl-paths');
// merged output file name. a folder of paths.packageName is temporarly created in build-dts
var jsName = paths.packageName + '.js';


// concats submodules into one file, compiles d.ts file and copies them to the dist folders
gulp.task('build-dts', function() {
var importsToAdd = []; // stores extracted imports

@@ -25,49 +25,65 @@ gulp.task('build-dts', function() {
this.push(file);
return callback();
}))
.pipe(concat(jsName)) // concat all selected files to jsName (now without their imports)
.pipe(to5(assign({}, compilerOptions.dts()))); // compile to d.ts from file jsName. d.ts file is in folder paths.packageName
.pipe(concat(jsName))
.pipe(to5(assign({}, compilerOptions.dts())));
});

gulp.task('build-es2015', ['build-html-es2015'], function() {
gulp.task('copy-dts', function() {
var tdsPath = paths.packageName + '/' + paths.packageName + '.d.ts';
return gulp.src(tdsPath)
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es2015'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('remove-dts-folder', function() {
var tdsFolder = paths.packageName;
return gulp.src([tdsFolder])
.pipe(vinylPaths(del));
});

// concats modules into one file
gulp.task('concat-modules', function() {
var importsToAdd = []; // stores extracted imports

return gulp.src(paths.source)
.pipe(tools.sortFiles())
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(jsName))
.pipe(gulp.dest(paths.output));
});

gulp.task('build-es2015', ['build-html-es2015'], function() {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.es2015())))
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-commonjs', ['build-html-commonjs'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.commonjs())))
.pipe(gulp.dest(paths.output + 'commonjs'));
});

gulp.task('build-amd', ['build-html-amd'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.amd())))
.pipe(gulp.dest(paths.output + 'amd'));
});

gulp.task('build-system', ['build-html-system'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.system())))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('copy-dts', function() {
var tdsPath = paths.packageName + '/' + paths.packageName + '.d.ts';
return gulp.src(tdsPath)
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es2015'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('remove-dts-folder', function() {
var tdsFolder = paths.packageName;
return gulp.src([tdsFolder])
.pipe(vinylPaths(del));
});

gulp.task('build-html-es2015', function() {
return gulp.src(paths.html)
@@ -92,10 +108,11 @@ gulp.task('build-html-system', function() {
gulp.task('build', function(callback) {
return runSequence(
'clean',
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
'copy-dts',
'remove-dts-folder',
'concat-modules',
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
callback
);
});
@@ -76,6 +76,7 @@
"gulp-bump": "^2.0.1",
"gulp-concat": "^2.6.0",
"gulp-eslint": "^1.1.1",
"gulp-insert": "^0.5.0",
"gulp-rename": "^1.2.2",
"gulp-typedoc": "^1.2.1",
"gulp-typedoc-extractor": "0.0.8",

0 comments on commit b471d57

Please sign in to comment.