Created
May 20, 2014 10:58
-
-
Save slorber/95fb1da7c73fa6d215cc to your computer and use it in GitHub Desktop.
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 browserify = require('browserify'); | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var handleErrors = require('../util/handleErrors'); | |
var source = require('vinyl-source-stream'); | |
var wrench = require('wrench'); | |
var path = require('path'); | |
var fs = require('fs'); | |
gulp.task('browserify', function(){ | |
function getSubdirectories(baseDir) { | |
return wrench.readdirSyncRecursive('./src/js/') | |
.map(function(filepath) { return path.join(baseDir, filepath) }) | |
.filter(function(filepath) { return fs.statSync(filepath).isDirectory(); }); | |
} | |
// This permits to lookup your files like node modules | |
// You can do require("mymodule") instead of require("../../../JS/dir/mymodule") | |
function getNodeModuleLookupPaths() { | |
var baseDir = "./src/js/"; | |
var jsPaths = getSubdirectories(baseDir); | |
jsPaths.unshift(baseDir); | |
jsPaths.unshift('./node_modules'); | |
gutil.log("NPM module Paths will be:\n"+jsPaths.join("\n")); | |
//return jsPaths; | |
return [ | |
'./node_modules', | |
//'./src/js/', | |
//'./src/js/common', | |
//'./src/js/home' | |
] | |
} | |
return browserify({ | |
entries: ['./src/js/app.js'], | |
extensions: ['.jsx'] | |
// paths: getNodeModuleLookupPaths() | |
}) | |
.bundle({debug: true}) | |
.on('error', handleErrors) | |
.pipe(source('app.js')) | |
.pipe(gulp.dest('./www')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment