Converting config into a module instead of just JSON

Allows the browserify config to be further unified. Also added ability
to build to different paths than just ./build
This commit is contained in:
Jeff Avallone 2014-11-30 14:39:56 -05:00
parent 30d88810d0
commit e910c757e5
4 changed files with 48 additions and 42 deletions

36
config.js Normal file
View File

@ -0,0 +1,36 @@
var path = require('path'),
_ = require('lodash'),
buildRoot = process.env.BUILD_PATH || './build',
buildPath = _.bind(path.join, path, buildRoot);
module.exports = {
buildRoot: buildRoot,
buildPath: buildPath,
templateFile: './template.html',
globs: {
other: './src/**/*.!(html|scss|js|peg)',
html: './src/**/*.html',
sass: './src/**/*.scss',
js: ['./src/**/*.js', './src/**/*.peg'],
spec: './spec/**/*_spec.js'
},
compass: {
sass: './src/sass',
css: buildPath('css'),
javascript: buildPath('js'),
font: buildPath('font'),
sourcemap: true
},
browserify: {
basedir: './src/js',
debug: true,
fullPaths: false,
prebundle: function(bundle) {
var es6ify = require('es6ify');
bundle.add(es6ify.runtime);
bundle.transform(require('./lib/canopy-transform'));
bundle.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/));
}
}
};

View File

@ -1,22 +0,0 @@
{
"templateFile": "./template.html",
"globs": {
"other": "./src/**/*.!(html|scss|js|peg)",
"html": "./src/**/*.html",
"sass": "./src/**/*.scss",
"js": ["./src/**/*.js", "./src/**/*.peg"],
"spec": "./spec/**/*_spec.js"
},
"compass": {
"sass": "./src/sass",
"css": "./build/css",
"javascript": "./build/js",
"font": "./build/font",
"sourcemap": true
},
"browserify": {
"basedir": "./src/js",
"debug": true,
"fullPaths": false
}
}

View File

@ -20,11 +20,11 @@ gulp.task('server', ['build'], function() {
var connect = require('gulp-connect'), var connect = require('gulp-connect'),
watch = require('gulp-watch'); watch = require('gulp-watch');
watch('./build/**/*', { name: 'Server' }) watch(config.buildPath('**/*'), { name: 'Server' })
.pipe(connect.reload()); .pipe(connect.reload());
return connect.server({ return connect.server({
root: './build', root: config.buildRoot,
livereload: true livereload: true
}); });
}); });
@ -32,18 +32,18 @@ gulp.task('server', ['build'], function() {
gulp.task('build', ['static', 'markup', 'compass', 'browserify']); gulp.task('build', ['static', 'markup', 'compass', 'browserify']);
gulp.task('static', function() { gulp.task('static', function() {
return gulp.src(config.globs.other, { base: 'src' }) return gulp.src(config.globs.other, { base: './src' })
.pipe(errorHandler()) .pipe(errorHandler())
.pipe(gulp.dest('./build')); .pipe(gulp.dest(config.buildRoot));
}); });
gulp.task('markup', function() { gulp.task('markup', function() {
var wrap = require('gulp-wrap'); var wrap = require('gulp-wrap');
return gulp.src(config.globs.html, { base: 'src' }) return gulp.src(config.globs.html, { base: './src' })
.pipe(errorHandler()) .pipe(errorHandler())
.pipe(wrap({ src: config.templateFile })) .pipe(wrap({ src: config.templateFile }))
.pipe(gulp.dest('./build')); .pipe(gulp.dest(config.buildRoot));
}); });
gulp.task('compass', function() { gulp.task('compass', function() {
@ -66,16 +66,16 @@ gulp.task('browserify', function() {
.pipe(tap(function(file) { .pipe(tap(function(file) {
var bundler = browserify(config.browserify); var bundler = browserify(config.browserify);
bundler.add([file.path, es6ify.runtime]); bundler.add(file.path);
bundler.transform(require('./lib/canopy-transform'));
bundler.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/)); config.browserify.prebundle(bundler);
file.contents = bundler.bundle(); file.contents = bundler.bundle();
})) }))
.pipe(transform(function() { .pipe(transform(function() {
return exorcist('./build/js/main.js.map'); return exorcist(config.buildPath('js/main.js.map'));
})) }))
.pipe(gulp.dest('./build/js')); .pipe(gulp.dest(config.buildPath('js')));
}); });
gulp.task('karma', function(done) { gulp.task('karma', function(done) {

View File

@ -17,14 +17,6 @@ module.exports = function(karma) {
browsers: ['PhantomJS'], browsers: ['PhantomJS'],
autoWatch: true, autoWatch: true,
singleRun: false, singleRun: false,
browserify: _.defaults({}, config.browserify, { browserify: config.browserify
prebundle: function(bundle) {
var es6ify = require('es6ify');
bundle.add([es6ify.runtime]);
bundle.transform(require('./lib/canopy-transform'));
bundle.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/));
}
})
}); });
}; };