浏览代码

Merge pull request #553 from RaananW/gulp-module-exports

Adding module exports
David Catuhe 10 年之前
父节点
当前提交
51345e97fb
共有 2 个文件被更改,包括 34 次插入0 次删除
  1. 31 0
      Tools/Gulp/gulp-addModuleExports.js
  2. 3 0
      Tools/Gulp/gulpfile.js

+ 31 - 0
Tools/Gulp/gulp-addModuleExports.js

@@ -0,0 +1,31 @@
+var gutil = require('gulp-util');
+var through = require('through2');
+
+module.exports = function (varName) {
+  return through.obj(function (file, enc, cb) {
+
+    var moduleExportsAddition = 
+      '\nif (module && module.exports) {\n' +
+      '    module.exports = ' + varName + ';\n' +
+      '};\n';
+
+    if (file.isNull()) {
+      cb(null, file);
+      return;
+    }
+
+    if (file.isStream()) {
+      //streams not supported, no need for now.
+      return;
+    }
+
+    try {
+      file.contents = new Buffer(String(file.contents).concat(moduleExportsAddition));
+      this.push(file);
+
+    } catch (err) {
+      this.emit('error', new gutil.PluginError('gulp-add-module-exports', err, {fileName: file.path}));
+    }
+    cb();
+  });
+};

+ 3 - 0
Tools/Gulp/gulpfile.js

@@ -3,6 +3,7 @@ var uglify = require("gulp-uglify");
 var typescript = require("gulp-typescript");
 var sourcemaps = require("gulp-sourcemaps");
 var srcToVariable = require("./gulp-srcToVariable");
+var addModuleExports = require("./gulp-addModuleExports");
 var merge2 = require("merge2");
 var concat = require("gulp-concat");
 var rename = require("gulp-rename");
@@ -77,6 +78,7 @@ gulp.task("buildNoWorker", ["shaders"], function () {
     )
     .pipe(concat(config.build.minNoWorkerFilename))
     .pipe(cleants())
+    .pipe(addModuleExports("BABYLON"))
     .pipe(uglify())
     .pipe(gulp.dest(config.build.outputDirectory))
 });
@@ -89,6 +91,7 @@ gulp.task("build", ["workers", "shaders"], function () {
     )
     .pipe(concat(config.build.filename))
     .pipe(cleants())
+    .pipe(addModuleExports("BABYLON"))
     .pipe(gulp.dest(config.build.outputDirectory))
     .pipe(rename(config.build.minFilename))
     .pipe(uglify())