Skip to content

Commit

Permalink
Merge 8004409 into ddaf3d0
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRave committed Oct 18, 2016
2 parents ddaf3d0 + 8004409 commit 9407c6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -29,8 +29,10 @@
"enb": ">= 0.15.0 <2.0.0"
},
"dependencies": {
"babel-core": "6.17.0",
"browserify": "11.1.0",
"enb-source-map": "1.8.0",
"micromatch": "2.3.11",
"uglify-js": "2.4.24",
"vow": "0.4.10",
"vow-node": "0.3.0",
Expand Down
21 changes: 19 additions & 2 deletions techs/browser-js.js
Expand Up @@ -4,6 +4,9 @@ var vow = require('vow'),
buildFlow = enb.buildFlow || require('enb/lib/build-flow'),
utils = require('enb-source-map/lib/utils'),
File = require('enb-source-map/lib/file'),
path = require('path'),
micromatch = require('micromatch'),
babelCore = require('babel-core'),
minify = require('uglify-js').minify;

/**
Expand All @@ -28,6 +31,9 @@ var vow = require('vow'),
* @param {Boolean} [options.compress=false] Minifies and compresses JS code.
* @param {Boolean} [options.sourcemap=false] Includes inline source maps.
* @param {Boolean} [options.includeYM=false] Prepends code of YModules.
* @param {String[]} [options.transpilePatterns=[]] File patterns to transpile.
* @param {String[]} [options.transpilePlugins=[]] Transpile plugins,<br>
* like http://babeljs.io/docs/plugins/
*
* @example
* // Code in a file system before build:
Expand Down Expand Up @@ -68,6 +74,8 @@ module.exports = buildFlow.create()
.defineOption('iife', false)
.defineOption('compress', false)
.defineOption('sourcemap', false)
.defineOption('transpilePatterns', [])
.defineOption('transpilePlugins', [])
.builder(function (sourceFiles) {
var promises = [this._readSourceFiles(sourceFiles)];

Expand Down Expand Up @@ -120,15 +128,24 @@ module.exports = buildFlow.create()
* @returns {FileData[]}
*/
_readSourceFiles: function (files) {
var node = this.node;
var node = this.node,
cwdPath = process.cwd(),
transpilePatterns = this._transpilePatterns,
babelOptions = {
plugins: this._transpilePlugins
};

return vow.all(files.map(function (file) {
return vfs.read(file.fullname, 'utf8')
.then(function (contents) {
var isMatch = micromatch.any(
path.relative(cwdPath, file.fullname),
transpilePatterns);

return {
path: file.fullname,
relPath: node.relativePath(file.fullname),
contents: contents
contents: isMatch ? babelCore.transform(contents, babelOptions).code : contents
};
});
}));
Expand Down

0 comments on commit 9407c6b

Please sign in to comment.