Skip to content

Commit

Permalink
Support for browserify (#28)
Browse files Browse the repository at this point in the history
* synchronize

* Clarify engine support:
Add engine support for nodejs through package.json. Fixes issue #12

* add support for browserify

* Update package.json
  • Loading branch information
david-gang authored and NoamaExl committed Jan 5, 2017
1 parent bf9cedd commit 59f619a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
18 changes: 17 additions & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ let customModuleFile = 'custom.module.js';
let customCssFile = 'custom1.css';
let mainFile = 'main.js';

let browserify;
let view ;
function setView(_view) {
view = _view;
}

function getBrowserify() {
return browserify;
}

function setBrowserify(_browserify) {
browserify = _browserify;
}

function getView(){
return view;
}
Expand All @@ -30,6 +39,10 @@ function mainPath() {
return viewJsDir()+'/*.js';
}

function mainJsPath() {
return viewJsDir()+'/main.js';
}

function customCssMainPath() {
return viewCssDir()+'/*.css';
}
Expand Down Expand Up @@ -79,6 +92,7 @@ let buildParams = {
customPath: customPath,
customModulePath: customModulePath,
mainPath: mainPath,
mainJsPath: mainJsPath,
viewJsDir: viewJsDir,
viewCssDir: viewCssDir,
customCssPath: customCssPath,
Expand All @@ -94,6 +108,8 @@ module.exports = {
buildParams: buildParams,
PROXY_SERVER: PROXY_SERVER,
setView: setView,
view: getView
view: getView,
getBrowserify: getBrowserify,
setBrowserify: setBrowserify
};

63 changes: 43 additions & 20 deletions gulp/tasks/buildCustomJs.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

let gulp = require('gulp');
let babel = require('gulp-babel');
let config = require('../config.js');
let rename = require("gulp-rename");
let concat = require("gulp-concat");
let debug = require('gulp-debug');
var wrap = require("gulp-wrap");
var glob = require('glob');
var gutil = require('gulp-util');
const gulp = require('gulp');
const babel = require('gulp-babel');
const config = require('../config.js');
const rename = require("gulp-rename");
const concat = require("gulp-concat");
const debug = require('gulp-debug');
const wrap = require("gulp-wrap");
const glob = require('glob');
const gutil = require('gulp-util');
const fs = require("fs");
const browserify = require("browserify");

let buildParams = config.buildParams;

Expand All @@ -19,24 +21,45 @@ gulp.task('watch-js', () => {


gulp.task('custom-js', () => {
if(config.getBrowserify()) {
buildByBrowserify();
}
else {
buildByConcatination();
}

});

function buildByConcatination() {
return gulp.src([buildParams.customModulePath(),buildParams.mainPath(),buildParams.customNpmJsPath(),'!'+buildParams.customPath(),'!'+buildParams.customNpmJsModulePath(),'!'+buildParams.customNpmJsCustomPath()])
.pipe(concat(buildParams.customFile))
.pipe(babel({
presets: ['es2015']
}))
.on("error", function(err) {
if (err && err.codeFrame) {
gutil.log(
gutil.colors.red("Browserify error: "),
gutil.colors.cyan(err.filename) + ` [${err.loc.line},${err.loc.column}]`,
"\r\n" + err.message + "\r\n" + err.codeFrame);
}
else {
gutil.log(err);
}
this.emit("end");
if (err && err.codeFrame) {
gutil.log(
gutil.colors.red("Browserify error: "),
gutil.colors.cyan(err.filename) + ` [${err.loc.line},${err.loc.column}]`,
"\r\n" + err.message + "\r\n" + err.codeFrame);
}
else {
gutil.log(err);
}
this.emit("end");
})
.pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();'))
.pipe(gulp.dest(buildParams.viewJsDir()));
}

});
function buildByBrowserify() {
return browserify({
entries: buildParams.mainJsPath(),
paths:[
buildParams.viewJsDir()+'/node_modules'
]
})
.transform("babelify",{presets: ["es2015"]})
.bundle()
.pipe(fs.createWriteStream(buildParams.customPath()));
}
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

var gulp = require('gulp');
var minimist = require('minimist');
var requireDir = require('require-dir');
const gulp = require('gulp');
const minimist = require('minimist');
const requireDir = require('require-dir');
requireDir('./gulp/tasks', { recurse: true });
var config = require('./gulp/config');
const config = require('./gulp/config');


var options = minimist(process.argv.slice(2));
config.setView(options.view);

config.setBrowserify(options.browserify);
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"author": "",
"devDependencies": {
"babel-preset-es2015": "6.6.0",
"babelify": "7.3.0",
"bluebird": "3.3.1",
"browser-sync": "2.9.9",
"browserify": "13.1.1",
"concat-stream": "1.5.1",
"connect-modrewrite": "0.8.2",
"css": "2.2.1",
Expand Down Expand Up @@ -40,6 +42,7 @@
"shelljs": "0.6.0",
"tar-fs": "1.13.0"
},
"engines" : { "node" : ">=4.2" }
"engines": {
"node": ">=4.2"
}
}

0 comments on commit 59f619a

Please sign in to comment.