diff --git a/README.md b/README.md index 7cf0a229..4bcc0d21 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Runs: - buildJs: `String` Name of the built JavaScript bundle. (Default: 'main.js') - buildFolder: `String` Path to directory where the built file will be created. If set to `'disabled'`, files won't be saved. (Default: './build/') - env: `String` It can be either 'production' or 'development'. If it's 'production', it will run [uglify](https://github.com/mishoo/UglifyJS2). If it's 'development', it will generate a sourcemap. (Default: 'development') + - cwd: `String` The path to the working directory, in which the code to be built exists. (Default: current working directory) - sourcemaps: `Boolean` Set to true to output sourcemaps, even if env is 'development'. (Default: false) - transforms: `Array` Additional browserify transforms to run *after* babelify, debowerify and textrequireify. Each transform should be specified as a - `Function` The transform function. e.g: `var brfs = require('brfs'); config.transform.push(brfs);` @@ -109,6 +110,7 @@ Runs: - autoprefixerBrowsers: `Array` An array of strings of [browser names for autoprefixer](https://github.com/postcss/autoprefixer#browsers) to check what prefixes it needs. (Default: `["> 1%", "last 2 versions", "ie > 6", "ff ESR"]`) - autoprefixerCascade: `Boolean` Whether autoprefixer should display CSS prefixed properties [cascaded](https://github.com/postcss/autoprefixer#visual-cascade) (Default: false) - autoprefixerRemove: `Boolean` Remove unneeded prefixes (Default: true) + - cwd: `String` The path to the working directory, in which the code to be built exists. (Default: current working directory) - buildCss: `String` Name of the built CSS bundle. (Default: 'main.css') - buildFolder: `String` Path to directory where the built file will be created. If set to `'disabled'`, files won't be saved. (Default: './build/') - env: `String` It can be either 'production' or 'development'. If it's 'production', it will compile the Sass file with the 'compressed' style option and will also run [clean-css](https://github.com/jakubpawlowicz/clean-css). (Default: development) diff --git a/lib/tasks/build.js b/lib/tasks/build.js index e9305592..3da63ad9 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -1,5 +1,6 @@ 'use strict'; +var path = require('path'); var browserify = require('browserify'); var source = require('vinyl-source-stream'); var buffer = require('vinyl-buffer'); @@ -39,10 +40,11 @@ module.exports = function(gulp, config) { module.exports.js = function(gulp, config) { config = config || {}; var src = config.js || files.getMainJsPath() || null; + var cwd = config.cwd || process.cwd(); if (src) { // See; https://github.com/substack/node-browserify#btransformtr-opts - var transforms = [babelify, debowerify, textrequireify.create({ - rootDirectory: process.cwd() + var transforms = [babelify, { transform: debowerify, options: { bowerOptions: { cwd: cwd, relative: true }}}, textrequireify.create({ + rootDirectory: cwd })].concat(config.transforms || []); config.env = config.env || 'development'; @@ -59,6 +61,10 @@ module.exports.js = function(gulp, config) { .require(src, { entry: true }); bundle = transforms.reduce(function(bundle, transform) { + if (transform.options && transform.transform) { + return bundle.transform(transform.transform, transform.options); + } + return bundle.transform(transform); }, bundle); @@ -90,6 +96,8 @@ module.exports.js = function(gulp, config) { module.exports.sass = function(gulp, config) { config = config || {}; var src = config.sass || files.getMainSassPath() || null; + var cwd = config.cwd || process.cwd(); + if (src) { var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildCss || 'main.css'; @@ -99,8 +107,9 @@ module.exports.sass = function(gulp, config) { config.env = config.env || 'development'; var useSourceMaps = config.sourcemaps === true || config.env === 'development'; + console.log("Current working directory: ", cwd); var sassConfig = { - includePaths: ['bower_components'].concat(config.sassIncludePaths || []), + includePaths: [path.join(cwd, 'bower_components')].concat(config.sassIncludePaths || []), outputStyle: config.env === 'production' ? 'compressed' : 'nested' };