From 23e12073ad7e7167b06d2b891f0002b78cf5701f Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Fri, 30 Jan 2015 16:29:10 +0100 Subject: [PATCH 01/36] [Add] lodash dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 34f9fa3..9612ad3 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "gulp-minify-css": "^0.3.11", "gulp-notify": "^2.0.0", "gulp-uglify": "^1.0.1", + "lodash": "^3.0.1", "main-bower-files": "^2.1.0" } } From bf090e08886e0a88cb4a30a0369358eae95457b8 Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Fri, 30 Jan 2015 16:56:01 +0100 Subject: [PATCH 02/36] [Upg] Handle font files and enable options instead of bower function arguments --- index.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index be6ca5d..7b10dbd 100644 --- a/index.js +++ b/index.js @@ -6,14 +6,28 @@ var notify = require('gulp-notify'); var minify = require('gulp-minify-css'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); +var _ = require('lodash'); -elixir.extend('bower', function(cssFile, cssOutput, jsFile, jsOutput) { +elixir.extend('bower', function(options) { var config = this; - var cssFile = cssFile || 'vendor.css'; - var jsFile = jsFile || 'vendor.js'; + + var options = _.merge({ + debug: false, + css: { + file: 'vendor.css', + output: config.cssOutput + }, + js: { + file: 'vendor.js', + output: config.jsOutput + }, + font: { + output: 'public/fonts' + } + }, options); - gulp.task('bower', ['bower-css', 'bower-js']); + gulp.task('bower', ['bower-css', 'bower-js', 'bower-fonts']); gulp.task('bower-css', function () { var onError = function (err) { @@ -27,12 +41,12 @@ elixir.extend('bower', function(cssFile, cssOutput, jsFile, jsOutput) { this.emit('end'); }; - return gulp.src(mainBowerFiles()) + return gulp.src(mainBowerFiles({debugging: options.debug})) .on('error', onError) .pipe(filter('**/*.css')) - .pipe(concat(cssFile)) + .pipe(concat(options.css.file)) .pipe(minify()) - .pipe(gulp.dest(cssOutput || config.cssOutput)) + .pipe(gulp.dest(options.css.output)) .pipe(notify({ title: 'Laravel Elixir', subtitle: 'CSS Bower Files Imported!', @@ -55,12 +69,12 @@ elixir.extend('bower', function(cssFile, cssOutput, jsFile, jsOutput) { this.emit('end'); }; - return gulp.src(mainBowerFiles()) + return gulp.src(mainBowerFiles({debugging: options.debug})) .on('error', onError) .pipe(filter('**/*.js')) - .pipe(concat(jsFile)) + .pipe(concat(options.js.file)) .pipe(uglify()) - .pipe(gulp.dest(jsOutput || config.jsOutput)) + .pipe(gulp.dest(options.js.output)) .pipe(notify({ title: 'Laravel Elixir', subtitle: 'Javascript Bower Files Imported!', @@ -69,6 +83,35 @@ elixir.extend('bower', function(cssFile, cssOutput, jsFile, jsOutput) { })); }); + + gulp.task('bower-fonts', function(){ + + var onError = function (err) { + + notify.onError({ + title: "Laravel Elixir", + subtitle: "Bower Files Font Copy Failed!", + message: "Error: <%= error.message %>", + icon: __dirname + '/../icons/fail.png' + })(err); + + this.emit('end'); + }; + + return gulp.src(mainBowerFiles({ + debugging: options.debug, + filter: (/\.(eot|svg|ttf|woff|otf)$/i) + })) + .on('error', onError) + .pipe(gulp.dest(options.font.output)) + .pipe(notify({ + title: 'Laravel Elixir', + subtitle: 'Font Bower Files Imported!', + icon: __dirname + '/../icons/laravel.png', + message: ' ' + })); + }); + return this.queueTask('bower'); From 1c3e41c6e0130f288549dcc750446cd86869f74a Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Fri, 30 Jan 2015 16:58:06 +0100 Subject: [PATCH 03/36] [Upg] Update readme --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 106f103..860000c 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,78 @@ laravel-elixir-bower Elixir Wrapper Around Bower -``` +### Usage + +```javascript var elixir = require('laravel-elixir'); require('laravel-elixir-bower'); elixir(function(mix) { - mix.bower() - .routes() - .events(); + mix.bower(); }); ``` -This will scan your bower files and concat all css files, by default, in a `css/vendor.css` file. And all js files in a `js/vendor.js` file. +This will : + - scan your bower files + - concat all css files in a `public/css/vendor.css` file + - concat all js files in a `public/js/vendor.js` file + - copy all webfonts in a `fonts/` folder. -These settings can be overwriten by passing them to the `bower()` function. +### Settings +The default settings are the following : + +```javascript +{ + debug: false, // Enable/Disable verbose output + css: { + file: 'vendor.css', // Merged CSS file + output: config.cssOutput // Elixir default css output folder (public/css) + }, + js: { + file: 'vendor.js', // Merged JS file + output: config.jsOutput // Elixir default js output folder (public/js) + }, + font: { + output: 'public/fonts' // Web fonts output folder + } +} ``` + +Each setting can be overwritten by passing them as an object to the `bower()` function. + +### Examples + +```javascript elixir(function(mix) { - mix.bower('styles.css', 'public/assets/css', 'scripts.js', 'public/assets/js'); + mix.bower({ + debug: true, + css: { + file: 'plugins.css' + }, + js: { + output: 'public/scripts' + } + }); }); -``` \ No newline at end of file +``` + +```javascript + +var options = {}; +options.debug = true; +options.css = {file: 'plugins.css'}; +options.js = {output: 'public/scripts'}; + +elixir(function(mix) { + mix.bower(options); +}); +``` + +Those examples doe the same : + - scan your bower files + - concat all css files in a `public/css/plugins.css` file + - concat all js files in a `public/scripts/vendor.js` file + - copy all webfonts in a `fonts/` folder. + From 1301bd11f48642dc2edcce636c986e1476a5d19f Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Fri, 30 Jan 2015 16:59:30 +0100 Subject: [PATCH 04/36] [Fix] Readme markdown lists --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 860000c..0ce65b9 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ elixir(function(mix) { ``` This will : - - scan your bower files - - concat all css files in a `public/css/vendor.css` file - - concat all js files in a `public/js/vendor.js` file - - copy all webfonts in a `fonts/` folder. +- scan your bower files +- concat all css files in a `public/css/vendor.css` file +- concat all js files in a `public/js/vendor.js` file +- copy all webfonts in a `fonts/` folder. ### Settings @@ -73,8 +73,8 @@ elixir(function(mix) { ``` Those examples doe the same : - - scan your bower files - - concat all css files in a `public/css/plugins.css` file - - concat all js files in a `public/scripts/vendor.js` file - - copy all webfonts in a `fonts/` folder. +- scan your bower files +- concat all css files in a `public/css/plugins.css` file +- concat all js files in a `public/scripts/vendor.js` file +- copy all webfonts in a `fonts/` folder. From 99c0403f706b5b9d051edd5302c84fa247dcb994 Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Wed, 4 Mar 2015 11:28:46 +0100 Subject: [PATCH 05/36] [Fix] Use debugging instead of debug, as main-bower-files does --- README.md | 6 +++--- index.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0ce65b9..9dcbf26 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The default settings are the following : ```javascript { - debug: false, // Enable/Disable verbose output + debugging: false, // Enable/Disable verbose output css: { file: 'vendor.css', // Merged CSS file output: config.cssOutput // Elixir default css output folder (public/css) @@ -49,7 +49,7 @@ Each setting can be overwritten by passing them as an object to the `bower()` fu ```javascript elixir(function(mix) { mix.bower({ - debug: true, + debugging: true, css: { file: 'plugins.css' }, @@ -63,7 +63,7 @@ elixir(function(mix) { ```javascript var options = {}; -options.debug = true; +options.debugging = true; options.css = {file: 'plugins.css'}; options.js = {output: 'public/scripts'}; diff --git a/index.js b/index.js index 7b10dbd..a3603d2 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ elixir.extend('bower', function(options) { var config = this; var options = _.merge({ - debug: false, + debugging: false, css: { file: 'vendor.css', output: config.cssOutput @@ -41,7 +41,7 @@ elixir.extend('bower', function(options) { this.emit('end'); }; - return gulp.src(mainBowerFiles({debugging: options.debug})) + return gulp.src(mainBowerFiles({debugging: options.debugging})) .on('error', onError) .pipe(filter('**/*.css')) .pipe(concat(options.css.file)) @@ -69,7 +69,7 @@ elixir.extend('bower', function(options) { this.emit('end'); }; - return gulp.src(mainBowerFiles({debugging: options.debug})) + return gulp.src(mainBowerFiles({debugging: options.debugging})) .on('error', onError) .pipe(filter('**/*.js')) .pipe(concat(options.js.file)) @@ -99,7 +99,7 @@ elixir.extend('bower', function(options) { }; return gulp.src(mainBowerFiles({ - debugging: options.debug, + debugging: options.debugging, filter: (/\.(eot|svg|ttf|woff|otf)$/i) })) .on('error', onError) From 5d3812adfed84671576bddcffc805ac8c328e840 Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Wed, 4 Mar 2015 12:48:57 +0100 Subject: [PATCH 06/36] [Fix] Handle woff2 fonts --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a3603d2..f5c8d70 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ elixir.extend('bower', function(options) { return gulp.src(mainBowerFiles({ debugging: options.debugging, - filter: (/\.(eot|svg|ttf|woff|otf)$/i) + filter: (/\.(eot|svg|ttf|woff|woff2|otf)$/i) })) .on('error', onError) .pipe(gulp.dest(options.font.output)) From 68bde13293902e0e4d18907ae4c3ea4a9c19e4fa Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Wed, 4 Mar 2015 17:19:51 +0100 Subject: [PATCH 07/36] [Upg] Add gulp-changed for fonts Font file not modified won't be copied, for a faster gulp process --- index.js | 2 ++ package.json | 1 + 2 files changed, 3 insertions(+) diff --git a/index.js b/index.js index f5c8d70..b8aef4e 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var notify = require('gulp-notify'); var minify = require('gulp-minify-css'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); +var changed = require('gulp-changed'); var _ = require('lodash'); elixir.extend('bower', function(options) { @@ -103,6 +104,7 @@ elixir.extend('bower', function(options) { filter: (/\.(eot|svg|ttf|woff|woff2|otf)$/i) })) .on('error', onError) + .pipe(changed(options.font.output)) .pipe(gulp.dest(options.font.output)) .pipe(notify({ title: 'Laravel Elixir', diff --git a/package.json b/package.json index 9612ad3..bc33e9b 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "url": "https://github.com/Crinsane/laravel-elixir-bower/issues" }, "dependencies": { + "gulp-changed": "^1.1.1", "gulp-concat": "^2.4.1", "gulp-filter": "^1.0.2", "gulp-load-plugins": "^0.7.0", From 3a330cfe0a4319675bb4407bf1fe166b0136b967 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Fri, 15 May 2015 21:31:19 +0200 Subject: [PATCH 08/36] Add image support --- index.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 6 +++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b8aef4e..9397b92 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,11 @@ var minify = require('gulp-minify-css'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); var changed = require('gulp-changed'); +var base64 = require('gulp-base64'); +var test = require('gulp-if'); +var ignore = require('gulp-ignore'); +var getFileSize = require("filesize"); + var _ = require('lodash'); elixir.extend('bower', function(options) { @@ -25,10 +30,15 @@ elixir.extend('bower', function(options) { }, font: { output: 'public/fonts' + }, + img: { + output: 'public/imgs', + extInline: [ 'gif', 'png'], + maxInlineSize: 32 * 1024 //max 32k on ie8 } }, options); - gulp.task('bower', ['bower-css', 'bower-js', 'bower-fonts']); + gulp.task('bower', ['bower-css', 'bower-js', 'bower-fonts', 'bower-imgs']); gulp.task('bower-css', function () { var onError = function (err) { @@ -45,6 +55,11 @@ elixir.extend('bower', function(options) { return gulp.src(mainBowerFiles({debugging: options.debugging})) .on('error', onError) .pipe(filter('**/*.css')) + .pipe(test(options.img.maxInlineSize > 0, base64({ + extensions: options.img.extInline, + maxImageSize: options.img.maxInlineSize, // bytes + debug: options.debugging, + }))) .pipe(concat(options.css.file)) .pipe(minify()) .pipe(gulp.dest(options.css.output)) @@ -113,6 +128,50 @@ elixir.extend('bower', function(options) { message: ' ' })); }); + + gulp.task('bower-imgs', function () { + + var onError = function (err) { + + notify.onError({ + title: "Laravel Elixir", + subtitle: "Bower Files Images Copy Failed!", + message: "Error: <%= error.message %>", + icon: __dirname + '/../icons/fail.png' + })(err); + + this.emit('end'); + }; + + var isInline = function (file) { + + var filesize = file.stat ? getFileSize(file.stat.size) : getFileSize(Buffer.byteLength(String(file.contents))); + var fileext = file.path.split('.').pop(); + + if (options.debugging) + { + console.log("Size of file:" + file.path + " (" + 1024*parseFloat(filesize) +" / max="+options.img.maxInlineSize+")"); + } + + return options.img.extInline.indexOf(fileext) > -1 && 1024*parseFloat(filesize) < options.img.maxInlineSize; + } + + return gulp.src(mainBowerFiles({ + debugging: options.debugging, + filter: (/\.(png|bmp|gif|jpg|jpeg)$/i) + })) + .on('error', onError) + .pipe(ignore.exclude(isInline)) // Exclude inlined images + .pipe(changed(options.img.output)) + .pipe(gulp.dest(options.img.output)) + .pipe(notify({ + title: 'Laravel Elixir', + subtitle: 'Images Bower Files Imported!', + icon: __dirname + '/../icons/laravel.png', + message: ' ' + })); + + }); return this.queueTask('bower'); diff --git a/package.json b/package.json index bc33e9b..520a7ca 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,10 @@ "gulp-notify": "^2.0.0", "gulp-uglify": "^1.0.1", "lodash": "^3.0.1", - "main-bower-files": "^2.1.0" + "main-bower-files": "^2.1.0", + "gulp-base64" :"^0.1.2", + "gulp-if" :"^1.2.5", + "gulp-ignore" :"^1.2.1", + "filesize":"^2.0.0" } } From c010fc38ab35dbe6bc4874680dba1d3420357912 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Fri, 15 May 2015 22:02:14 +0200 Subject: [PATCH 09/36] Update documentation --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9dcbf26..c4a2448 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ This will : - concat all css files in a `public/css/vendor.css` file - concat all js files in a `public/js/vendor.js` file - copy all webfonts in a `fonts/` folder. +- copy all images in a `imgs/` folder. ### Settings @@ -38,6 +39,12 @@ The default settings are the following : }, font: { output: 'public/fonts' // Web fonts output folder + }, + img: { + output: 'public/imgs', + extInline: ['gif','png'], // Extensions to inline + maxInlineSize: 32 * 1024 // [kB] Inline as data uri images below specified size + // (use 0 to disable, max 32k on ie8) } } ``` @@ -72,7 +79,7 @@ elixir(function(mix) { }); ``` -Those examples doe the same : +Those examples do the same : - scan your bower files - concat all css files in a `public/css/plugins.css` file - concat all js files in a `public/scripts/vendor.js` file From 457d50770f2edc7a0f7cbad06d78ec61c78dad68 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Fri, 15 May 2015 17:08:06 -0400 Subject: [PATCH 10/36] Made all file types optional by checking for false value first. --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9397b92..ba12f1f 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,14 @@ elixir.extend('bower', function(options) { } }, options); - gulp.task('bower', ['bower-css', 'bower-js', 'bower-fonts', 'bower-imgs']); + var files = []; + + if(options.css !== false) files.push('bower-css'); + if(options.js !== false) files.push('bower-js'); + if(options.font !== false) files.push('bower-fonts'); + if(options.img !== false) files.push('bower-imgs'); + + gulp.task('bower', files ); gulp.task('bower-css', function () { var onError = function (err) { From 0a011c0e605b48659792651c86687536ec3f01d2 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 21 May 2015 22:58:57 +0200 Subject: [PATCH 11/36] [Upg] Add default config [Rmv] Hardcoded ref to public dir --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9397b92..e52959e 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ var getFileSize = require("filesize"); var _ = require('lodash'); -elixir.extend('bower', function(options) { +elixir.extend('bower', function (options) { var config = this; @@ -22,18 +22,18 @@ elixir.extend('bower', function(options) { debugging: false, css: { file: 'vendor.css', - output: config.cssOutput + output: config.cssOutput ? config.cssOutput : config.publicDir + '/css' }, js: { file: 'vendor.js', - output: config.jsOutput + output: config.jsOutput ? config.jsOutput : config.publicDir + '/js' }, font: { - output: 'public/fonts' + output: config.fontOutput ? config.fontOutput : config.publicDir + '/fonts' }, img: { - output: 'public/imgs', - extInline: [ 'gif', 'png'], + output: config.imgOutput ? config.imgOutput : config.publicDir + '/imgs', + extInline: ['gif', 'png'], maxInlineSize: 32 * 1024 //max 32k on ie8 } }, options); From b1329da305f2e520002c514c32195ace57589648 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Mon, 29 Jun 2015 23:10:38 +0200 Subject: [PATCH 12/36] [Upd] minify/uglify as options --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e52959e..f971971 100644 --- a/index.js +++ b/index.js @@ -21,10 +21,12 @@ elixir.extend('bower', function (options) { var options = _.merge({ debugging: false, css: { + minify : true, file: 'vendor.css', output: config.cssOutput ? config.cssOutput : config.publicDir + '/css' }, js: { + uglify : true, file: 'vendor.js', output: config.jsOutput ? config.jsOutput : config.publicDir + '/js' }, @@ -61,7 +63,7 @@ elixir.extend('bower', function (options) { debug: options.debugging, }))) .pipe(concat(options.css.file)) - .pipe(minify()) + .pipe(test(options.css.minify,minify())) .pipe(gulp.dest(options.css.output)) .pipe(notify({ title: 'Laravel Elixir', @@ -89,7 +91,7 @@ elixir.extend('bower', function (options) { .on('error', onError) .pipe(filter('**/*.js')) .pipe(concat(options.js.file)) - .pipe(uglify()) + .pipe(test(options.js.uglify,uglify())) .pipe(gulp.dest(options.js.output)) .pipe(notify({ title: 'Laravel Elixir', @@ -176,4 +178,4 @@ elixir.extend('bower', function (options) { return this.queueTask('bower'); -}); \ No newline at end of file +}); From 62b4f276c595ead600791ec55e207beb7616e53b Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Sun, 16 Aug 2015 21:35:24 -0400 Subject: [PATCH 13/36] Prepare current package for Elixir upgrade by pinning it to v2.x --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 520a7ca..e7f2ea1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "laravel-elixir-bower", - "version": "0.1.0", + "version": "0.1.1", "description": "Laravel Elixir Bower Extension", "main": "index.js", "scripts": { @@ -36,5 +36,8 @@ "gulp-if" :"^1.2.5", "gulp-ignore" :"^1.2.1", "filesize":"^2.0.0" + }, + "peerDependencies":{ + "laravel-elixir":"^2.0" } } From 5903a69ce64cfd4bb3239381c016da2171d65b09 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Sun, 16 Aug 2015 21:38:44 -0400 Subject: [PATCH 14/36] Update version of laravel elixir and bump major version of package for upgrade. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e7f2ea1..7667d7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "laravel-elixir-bower", - "version": "0.1.1", + "version": "1.0.0", "description": "Laravel Elixir Bower Extension", "main": "index.js", "scripts": { @@ -38,6 +38,6 @@ "filesize":"^2.0.0" }, "peerDependencies":{ - "laravel-elixir":"^2.0" + "laravel-elixir":"^3.0" } } From 3d696c71f42305d14f56e6a9bf29ebbf47895f82 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 2 Sep 2015 00:53:48 -0400 Subject: [PATCH 15/36] Updated readme with optional example. --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index c4a2448..b1916ff 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ The default settings are the following : Each setting can be overwritten by passing them as an object to the `bower()` function. +Any setting can also be set to `false` to prevent generation and output of those files. + ### Examples ```javascript @@ -85,3 +87,27 @@ Those examples do the same : - concat all js files in a `public/scripts/vendor.js` file - copy all webfonts in a `fonts/` folder. +```javascript +elixir(function(mix) { + mix.bower({ + debugging: true, + css: false, + js: false, + font: { + output: 'public/fonts' + }, + img: { + output: 'public/css', + extInline: ['gif', 'png'], // Extensions to inline + maxInlineSize: 32 * 1024 // [kB] Inline as data uri images below specified size + // (use 0 to disable, max 32k on ie8) + } + }); +}); +``` +This example does the following: +- scan your bower files +- skips css and js files +- copy all webfonts in a `public/fonts/` folder. +- copy all gif or png images into `public/css` folder. +- inline any of those images which are smaller than 32k. From 11fcdc35c7ebe5273bc3bcb2f6d0abc8da242f7c Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 2 Sep 2015 01:11:33 -0400 Subject: [PATCH 16/36] Updaed with new elixir config and folder paths. --- index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index f971971..a652892 100644 --- a/index.js +++ b/index.js @@ -12,29 +12,30 @@ var test = require('gulp-if'); var ignore = require('gulp-ignore'); var getFileSize = require("filesize"); +var config = elixir.config; + + var _ = require('lodash'); elixir.extend('bower', function (options) { - var config = this; - var options = _.merge({ debugging: false, css: { minify : true, file: 'vendor.css', - output: config.cssOutput ? config.cssOutput : config.publicDir + '/css' + output: config.css.outputFolder ? config.css.outputFolder : config.publicPath + '/css' }, js: { uglify : true, file: 'vendor.js', - output: config.jsOutput ? config.jsOutput : config.publicDir + '/js' + output: config.js.outputFolder ? config.js.outputFolder : config.publicPath + '/js' }, font: { - output: config.fontOutput ? config.fontOutput : config.publicDir + '/fonts' + output: config.font.outputFolder ? config.font.outputFolder : config.publicPath + '/fonts' }, img: { - output: config.imgOutput ? config.imgOutput : config.publicDir + '/imgs', + output: config.img.outputFolder ? config.img.outputFolder : config.publicPath + '/imgs', extInline: ['gif', 'png'], maxInlineSize: 32 * 1024 //max 32k on ie8 } From 26c2660efc302abc27b54d2de8ced7fc43d59e61 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 2 Sep 2015 01:26:36 -0400 Subject: [PATCH 17/36] Added new task system. Calling start on bower task. --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a652892..c8a7400 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ var test = require('gulp-if'); var ignore = require('gulp-ignore'); var getFileSize = require("filesize"); +var task = elixir.Task; var config = elixir.config; @@ -175,8 +176,9 @@ elixir.extend('bower', function (options) { })); }); - - return this.queueTask('bower'); + new task('bower',function(){ + return gulp.start('bower'); + }); }); From 512c039119be35d6357ca069463773dd6fbfba5d Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 2 Sep 2015 01:31:28 -0400 Subject: [PATCH 18/36] Check for future posible font or img configurations before checking for an output folder. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c8a7400..bffc2f8 100644 --- a/index.js +++ b/index.js @@ -33,10 +33,10 @@ elixir.extend('bower', function (options) { output: config.js.outputFolder ? config.js.outputFolder : config.publicPath + '/js' }, font: { - output: config.font.outputFolder ? config.font.outputFolder : config.publicPath + '/fonts' + output: (config.font && config.font.outputFolder) ? config.font.outputFolder : config.publicPath + '/fonts' }, img: { - output: config.img.outputFolder ? config.img.outputFolder : config.publicPath + '/imgs', + output: (config.img && config.img.outputFolder) ? config.img.outputFolder : config.publicPath + '/imgs', extInline: ['gif', 'png'], maxInlineSize: 32 * 1024 //max 32k on ie8 } From ad8d39b87592b1843fca85fb115c69a817f08df4 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 2 Sep 2015 01:58:58 -0400 Subject: [PATCH 19/36] Updated task and output folders for default config. --- index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 169814f..5c27f14 100644 --- a/index.js +++ b/index.js @@ -25,18 +25,18 @@ elixir.extend('bower', function (options) { css: { minify : true, file: 'vendor.css', - output: config.css.outputFolder ? config.css.outputFolder : config.publicPath + '/css' + output: config.css.outputFolder ? config.publicPath + '/' + config.css.outputFolder : config.publicPath + '/css' }, js: { uglify : true, file: 'vendor.js', - output: config.js.outputFolder ? config.js.outputFolder : config.publicPath + '/js' + output: config.js.outputFolder ? config.publicPath + '/' + config.js.outputFolder : config.publicPath + '/js' }, font: { - output: (config.font && config.font.outputFolder) ? config.font.outputFolder : config.publicPath + '/fonts' + output: (config.font && config.font.outputFolder) ? config.publicPath + '/' + config.font.outputFolder : config.publicPath + '/fonts' }, img: { - output: (config.img && config.img.outputFolder) ? config.img.outputFolder : config.publicPath + '/imgs', + output: (config.img && config.img.outputFolder) ? config.publicPath + '/' + config.img.outputFolder : config.publicPath + '/imgs', extInline: ['gif', 'png'], maxInlineSize: 32 * 1024 //max 32k on ie8 } @@ -49,7 +49,9 @@ elixir.extend('bower', function (options) { if(options.font !== false) files.push('bower-fonts'); if(options.img !== false) files.push('bower-imgs'); - gulp.task('bower', files ); + new task('bower', function () { + return gulp.start(files); + }); gulp.task('bower-css', function () { var onError = function (err) { @@ -184,8 +186,4 @@ elixir.extend('bower', function (options) { }); - new task('bower',function(){ - return gulp.start('bower'); - }); - }); From 4d4248f646fdac155a9aa8dabc985b735ded9d7b Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Tue, 20 Oct 2015 21:46:39 +0200 Subject: [PATCH 20/36] [Upd] Notifications --- index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 5c27f14..b66fe7e 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ elixir.extend('bower', function (options) { notify.onError({ title: "Laravel Elixir", subtitle: "Bower Files CSS Compilation Failed!", - message: "Error: <%= error.message %>", + message: "Bower Files CSS Compilation Failed! Error: <%= error.message %>", icon: __dirname + '/../icons/fail.png' })(err); @@ -80,7 +80,7 @@ elixir.extend('bower', function (options) { title: 'Laravel Elixir', subtitle: 'CSS Bower Files Imported!', icon: __dirname + '/../icons/laravel.png', - message: ' ' + message: 'CSS Bower Files Imported!' })); }); @@ -91,7 +91,7 @@ elixir.extend('bower', function (options) { notify.onError({ title: "Laravel Elixir", subtitle: "Bower Files JS Compilation Failed!", - message: "Error: <%= error.message %>", + message: "Bower Files JS Compilation Failed! Error: <%= error.message %>", icon: __dirname + '/../icons/fail.png' })(err); @@ -108,7 +108,7 @@ elixir.extend('bower', function (options) { title: 'Laravel Elixir', subtitle: 'Javascript Bower Files Imported!', icon: __dirname + '/../icons/laravel.png', - message: ' ' + message: 'Javascript Bower Files Imported!' })); }); @@ -120,7 +120,7 @@ elixir.extend('bower', function (options) { notify.onError({ title: "Laravel Elixir", subtitle: "Bower Files Font Copy Failed!", - message: "Error: <%= error.message %>", + message: "Bower Files Font Copy Failed! Error: <%= error.message %>", icon: __dirname + '/../icons/fail.png' })(err); @@ -138,7 +138,7 @@ elixir.extend('bower', function (options) { title: 'Laravel Elixir', subtitle: 'Font Bower Files Imported!', icon: __dirname + '/../icons/laravel.png', - message: ' ' + message: 'Font Bower Files Imported!' })); }); @@ -149,7 +149,7 @@ elixir.extend('bower', function (options) { notify.onError({ title: "Laravel Elixir", subtitle: "Bower Files Images Copy Failed!", - message: "Error: <%= error.message %>", + message: "Bower Files Images Copy Failed! Error: <%= error.message %>", icon: __dirname + '/../icons/fail.png' })(err); @@ -179,9 +179,8 @@ elixir.extend('bower', function (options) { .pipe(gulp.dest(options.img.output)) .pipe(notify({ title: 'Laravel Elixir', - subtitle: 'Images Bower Files Imported!', icon: __dirname + '/../icons/laravel.png', - message: ' ' + message: 'Images Bower Files Imported!' })); }); From 3aba4c611a7f2a8b3f0f7a003dda45952960e3a1 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Tue, 20 Oct 2015 22:46:08 +0200 Subject: [PATCH 21/36] [Upd] Re-use laravel-elixir notification system --- index.js | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index b66fe7e..48e7695 100644 --- a/index.js +++ b/index.js @@ -76,12 +76,7 @@ elixir.extend('bower', function (options) { .pipe(concat(options.css.file)) .pipe(test(options.css.minify,minify())) .pipe(gulp.dest(options.css.output)) - .pipe(notify({ - title: 'Laravel Elixir', - subtitle: 'CSS Bower Files Imported!', - icon: __dirname + '/../icons/laravel.png', - message: 'CSS Bower Files Imported!' - })); + .pipe(new elixir.Notification('CSS Bower Files Imported!')); }); @@ -104,12 +99,7 @@ elixir.extend('bower', function (options) { .pipe(concat(options.js.file)) .pipe(test(options.js.uglify,uglify())) .pipe(gulp.dest(options.js.output)) - .pipe(notify({ - title: 'Laravel Elixir', - subtitle: 'Javascript Bower Files Imported!', - icon: __dirname + '/../icons/laravel.png', - message: 'Javascript Bower Files Imported!' - })); + .pipe(new elixir.Notification('Javascript Bower Files Imported!')); }); @@ -126,7 +116,7 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - + return gulp.src(mainBowerFiles({ debugging: options.debugging, filter: (/\.(eot|svg|ttf|woff|woff2|otf)$/i) @@ -134,12 +124,7 @@ elixir.extend('bower', function (options) { .on('error', onError) .pipe(changed(options.font.output)) .pipe(gulp.dest(options.font.output)) - .pipe(notify({ - title: 'Laravel Elixir', - subtitle: 'Font Bower Files Imported!', - icon: __dirname + '/../icons/laravel.png', - message: 'Font Bower Files Imported!' - })); + .pipe(new elixir.Notification('Font Bower Files Imported!')); }); gulp.task('bower-imgs', function () { @@ -177,11 +162,7 @@ elixir.extend('bower', function (options) { .pipe(ignore.exclude(isInline)) // Exclude inlined images .pipe(changed(options.img.output)) .pipe(gulp.dest(options.img.output)) - .pipe(notify({ - title: 'Laravel Elixir', - icon: __dirname + '/../icons/laravel.png', - message: 'Images Bower Files Imported!' - })); + .pipe(new elixir.Notification('Images Bower Files Imported!')); }); From 4f9aa092f7cf4d734c1434cae2efa94c5373049a Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Wed, 21 Oct 2015 19:32:31 +0200 Subject: [PATCH 22/36] [Upd] Filesize usage --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 48e7695..7c6be77 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ var changed = require('gulp-changed'); var base64 = require('gulp-base64'); var test = require('gulp-if'); var ignore = require('gulp-ignore'); -var getFileSize = require("filesize"); +var filesize = require('filesize'); var task = elixir.Task; var config = elixir.config; @@ -143,15 +143,15 @@ elixir.extend('bower', function (options) { var isInline = function (file) { - var filesize = file.stat ? getFileSize(file.stat.size) : getFileSize(Buffer.byteLength(String(file.contents))); - var fileext = file.path.split('.').pop(); + var fsize = file.stat ? filesize(file.stat.size) : filesize(Buffer.byteLength(String(file.contents))); + var fext = file.path.split('.').pop(); if (options.debugging) { - console.log("Size of file:" + file.path + " (" + 1024*parseFloat(filesize) +" / max="+options.img.maxInlineSize+")"); + console.log("Size of file:" + file.path + " (" + 1024*parseFloat(fsize) +" / max="+options.img.maxInlineSize+")"); } - return options.img.extInline.indexOf(fileext) > -1 && 1024*parseFloat(filesize) < options.img.maxInlineSize; + return options.img.extInline.indexOf(fext) > -1 && 1024*parseFloat(fsize) < options.img.maxInlineSize; } return gulp.src(mainBowerFiles({ From fa881e098cb3175ea2bef1781970ff044a2563d3 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Wed, 21 Oct 2015 19:34:28 +0200 Subject: [PATCH 23/36] [Upd] Rename bowerfile plugin --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7c6be77..5c3b210 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ var gulp = require('gulp'); -var mainBowerFiles = require('main-bower-files'); +var bowerfiles = require('main-bower-files'); var elixir = require('laravel-elixir'); var filter = require('gulp-filter'); var notify = require('gulp-notify'); @@ -65,7 +65,7 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(mainBowerFiles({debugging: options.debugging})) + return gulp.src(bowerfiles({debugging: options.debugging})) .on('error', onError) .pipe(filter('**/*.css')) .pipe(test(options.img.maxInlineSize > 0, base64({ @@ -93,7 +93,7 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(mainBowerFiles({debugging: options.debugging})) + return gulp.src(bowerfiles({debugging: options.debugging})) .on('error', onError) .pipe(filter('**/*.js')) .pipe(concat(options.js.file)) @@ -117,7 +117,7 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(mainBowerFiles({ + return gulp.src(bowerfiles({ debugging: options.debugging, filter: (/\.(eot|svg|ttf|woff|woff2|otf)$/i) })) @@ -154,7 +154,7 @@ elixir.extend('bower', function (options) { return options.img.extInline.indexOf(fext) > -1 && 1024*parseFloat(fsize) < options.img.maxInlineSize; } - return gulp.src(mainBowerFiles({ + return gulp.src(bowerfiles({ debugging: options.debugging, filter: (/\.(png|bmp|gif|jpg|jpeg)$/i) })) From 1b89b1d7441d9df2450ba3e1ded67870d65036ff Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Wed, 21 Oct 2015 19:57:56 +0200 Subject: [PATCH 24/36] [Upd] Standardized notifications --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5c3b210..93d7d50 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ var filesize = require('filesize'); var task = elixir.Task; var config = elixir.config; +var notification = elixir.Notification; var _ = require('lodash'); @@ -76,7 +77,7 @@ elixir.extend('bower', function (options) { .pipe(concat(options.css.file)) .pipe(test(options.css.minify,minify())) .pipe(gulp.dest(options.css.output)) - .pipe(new elixir.Notification('CSS Bower Files Imported!')); + .pipe(new notification('CSS Bower Files Imported!')); }); @@ -99,7 +100,7 @@ elixir.extend('bower', function (options) { .pipe(concat(options.js.file)) .pipe(test(options.js.uglify,uglify())) .pipe(gulp.dest(options.js.output)) - .pipe(new elixir.Notification('Javascript Bower Files Imported!')); + .pipe(new notification('Javascript Bower Files Imported!')); }); @@ -124,7 +125,7 @@ elixir.extend('bower', function (options) { .on('error', onError) .pipe(changed(options.font.output)) .pipe(gulp.dest(options.font.output)) - .pipe(new elixir.Notification('Font Bower Files Imported!')); + .pipe(new notification('Font Bower Files Imported!')); }); gulp.task('bower-imgs', function () { @@ -162,7 +163,7 @@ elixir.extend('bower', function (options) { .pipe(ignore.exclude(isInline)) // Exclude inlined images .pipe(changed(options.img.output)) .pipe(gulp.dest(options.img.output)) - .pipe(new elixir.Notification('Images Bower Files Imported!')); + .pipe(new notification('Images Bower Files Imported!')); }); From 1bc30e4612db919b9036c6ea0677763a0186706c Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Wed, 21 Oct 2015 20:04:26 +0200 Subject: [PATCH 25/36] [Add] Dependencies --- index.js | 4 +++- package.json | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 93d7d50..79203e2 100644 --- a/index.js +++ b/index.js @@ -11,12 +11,14 @@ var base64 = require('gulp-base64'); var test = require('gulp-if'); var ignore = require('gulp-ignore'); var filesize = require('filesize'); +var rework = require('rework'); +var path = require('path'); +var validator = require('validator'); var task = elixir.Task; var config = elixir.config; var notification = elixir.Notification; - var _ = require('lodash'); elixir.extend('bower', function (options) { diff --git a/package.json b/package.json index 7667d7f..8c56a60 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,9 @@ "gulp-base64" :"^0.1.2", "gulp-if" :"^1.2.5", "gulp-ignore" :"^1.2.1", - "filesize":"^2.0.0" + "filesize":"^2.0.0", + "rework": "^0.20.2", + "validator": "^3.1.0" }, "peerDependencies":{ "laravel-elixir":"^3.0" From bd946cf597ce4b307bf934520d5805a7d5a2fab6 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 22 Oct 2015 00:06:47 +0200 Subject: [PATCH 26/36] [Add] New packages --- package.json | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 8c56a60..51550e9 100644 --- a/package.json +++ b/package.json @@ -23,21 +23,23 @@ "url": "https://github.com/Crinsane/laravel-elixir-bower/issues" }, "dependencies": { - "gulp-changed": "^1.1.1", - "gulp-concat": "^2.4.1", - "gulp-filter": "^1.0.2", - "gulp-load-plugins": "^0.7.0", - "gulp-minify-css": "^0.3.11", - "gulp-notify": "^2.0.0", - "gulp-uglify": "^1.0.1", - "lodash": "^3.0.1", - "main-bower-files": "^2.1.0", - "gulp-base64" :"^0.1.2", - "gulp-if" :"^1.2.5", - "gulp-ignore" :"^1.2.1", - "filesize":"^2.0.0", - "rework": "^0.20.2", - "validator": "^3.1.0" + "gulp-changed": "^1.1", + "gulp-concat": "^2.4", + "gulp-filter": "^1.0", + "gulp-load-plugins": "^0.7", + "gulp-minify-css": "^0.3", + "gulp-notify": "^2.0", + "gulp-uglify": "^1.0", + "lodash": "^3.0", + "main-bower-files": "^2.1", + "gulp-base64" :"^0.1", + "gulp-if" :"^1.2", + "gulp-ignore" :"^1.2", + "gulp-rewrite-css":"^0.0", + "filesize":"^2.0", + "validator": "^4.2", + "is-absolute-url":"^2.0" + }, "peerDependencies":{ "laravel-elixir":"^3.0" From 5e3746254d5ec98af60d6209bf88d2390c17bab1 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 22 Oct 2015 00:07:14 +0200 Subject: [PATCH 27/36] [Add] css rewrite support --- index.js | 186 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 97 insertions(+), 89 deletions(-) diff --git a/index.js b/index.js index 79203e2..780bf38 100644 --- a/index.js +++ b/index.js @@ -10,10 +10,11 @@ var changed = require('gulp-changed'); var base64 = require('gulp-base64'); var test = require('gulp-if'); var ignore = require('gulp-ignore'); +var rewrite = require('gulp-rewrite-css'); var filesize = require('filesize'); -var rework = require('rework'); -var path = require('path'); +var path = require('path'); var validator = require('validator'); +var isAbsolute = require('is-absolute-url'); var task = elixir.Task; var config = elixir.config; @@ -26,146 +27,153 @@ elixir.extend('bower', function (options) { var options = _.merge({ debugging: false, css: { - minify : true, + minify: true, file: 'vendor.css', + extInline: ['gif', 'png' ], + maxInlineSize: 32 * 1024, //max 32k on ie8 output: config.css.outputFolder ? config.publicPath + '/' + config.css.outputFolder : config.publicPath + '/css' }, js: { - uglify : true, + uglify: true, file: 'vendor.js', output: config.js.outputFolder ? config.publicPath + '/' + config.js.outputFolder : config.publicPath + '/js' }, font: { - output: (config.font && config.font.outputFolder) ? config.publicPath + '/' + config.font.outputFolder : config.publicPath + '/fonts' + output: (config.font && config.font.outputFolder) ? config.publicPath + '/' + config.font.outputFolder : config.publicPath + '/fonts', + filter: /\.(eot|svg|ttf|woff|woff2|otf)$/i }, img: { output: (config.img && config.img.outputFolder) ? config.publicPath + '/' + config.img.outputFolder : config.publicPath + '/imgs', - extInline: ['gif', 'png'], - maxInlineSize: 32 * 1024 //max 32k on ie8 + filter: /\.(png|bmp|gif|jpg|jpeg)$/i + } }, options); var files = []; - if(options.css !== false) files.push('bower-css'); - if(options.js !== false) files.push('bower-js'); - if(options.font !== false) files.push('bower-fonts'); - if(options.img !== false) files.push('bower-imgs'); + if (options.css !== false) + files.push('bower-css'); + if (options.js !== false) + files.push('bower-js'); + if (options.font !== false) + files.push('bower-fonts'); + if (options.img !== false) + files.push('bower-imgs'); new task('bower', function () { return gulp.start(files); }); + var isInline = function (file) { + + var fsize = file.stat ? filesize(file.stat.size) : filesize(Buffer.byteLength(String(file.contents))); + var fext = file.path.split('.').pop(); + + if (options.debugging) + console.log("Size of file:" + file.path + " (" + 1024 * parseFloat(fsize) + " / max=" + options.css.maxInlineSize + ")"); + + return options.css.extInline.indexOf(fext) > -1 && 1024 * parseFloat(fsize) < options.css.maxInlineSize; + } + gulp.task('bower-css', function () { - var onError = function (err) { - notify.onError({ - title: "Laravel Elixir", - subtitle: "Bower Files CSS Compilation Failed!", - message: "Bower Files CSS Compilation Failed! Error: <%= error.message %>", - icon: __dirname + '/../icons/fail.png' - })(err); + var onError = function (err) { + new notification().error(err, "Bower Files CSS Compilation Failed! Error: <%= error.message %>"); this.emit('end'); }; + var rebase = function (context) { + + if (isAbsolute(context.targetFile) || validator.isURL(context.targetFile) || context.targetFile.indexOf('data:image') === 0) { + return context.targetFile; + } + + var absolutePath = context.targetFile.split('?').shift(); + + var p = ""; + + if (absolutePath.match(options.font.filter)) + p = path.relative(context.destinationDir, process.cwd() + '/' + options.font.output + '/' + context.targetFile.split('/').pop()); + + if (absolutePath.match(options.img.filter)) + p = path.relative(context.destinationDir, process.cwd() + '/' + options.img.output + '/' + context.targetFile.split('/').pop()); + + if (process.platform === 'win32') + p = p.replace(/\\/g, '/'); + + return p; + + }; + + + return gulp.src(bowerfiles({debugging: options.debugging})) - .on('error', onError) - .pipe(filter('**/*.css')) - .pipe(test(options.img.maxInlineSize > 0, base64({ - extensions: options.img.extInline, - maxImageSize: options.img.maxInlineSize, // bytes - debug: options.debugging, - }))) - .pipe(concat(options.css.file)) - .pipe(test(options.css.minify,minify())) - .pipe(gulp.dest(options.css.output)) - .pipe(new notification('CSS Bower Files Imported!')); + .on('error', onError) + .pipe(filter('**/*.css')) + .pipe(test(options.css.maxInlineSize > 0, base64({ + extensions: options.css.extInline, + maxImageSize: options.css.maxInlineSize, // bytes + debug: options.debugging, + }))) + .pipe(rewrite({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) + .pipe(concat(options.css.file)) + .pipe(test(options.css.minify, minify())) + .pipe(gulp.dest(options.css.output)) + .pipe(new notification('CSS Bower Files Imported!')); }); gulp.task('bower-js', function () { - var onError = function (err) { - - notify.onError({ - title: "Laravel Elixir", - subtitle: "Bower Files JS Compilation Failed!", - message: "Bower Files JS Compilation Failed! Error: <%= error.message %>", - icon: __dirname + '/../icons/fail.png' - })(err); + var onError = function (err) { + new notification().error(err, "Bower Files JS Compilation Failed! Error: <%= error.message %>"); this.emit('end'); }; return gulp.src(bowerfiles({debugging: options.debugging})) - .on('error', onError) - .pipe(filter('**/*.js')) - .pipe(concat(options.js.file)) - .pipe(test(options.js.uglify,uglify())) - .pipe(gulp.dest(options.js.output)) - .pipe(new notification('Javascript Bower Files Imported!')); + .on('error', onError) + .pipe(filter('**/*.js')) + .pipe(concat(options.js.file)) + .pipe(test(options.js.uglify, uglify())) + .pipe(gulp.dest(options.js.output)) + .pipe(new notification('Javascript Bower Files Imported!')); }); - - gulp.task('bower-fonts', function(){ - - var onError = function (err) { - notify.onError({ - title: "Laravel Elixir", - subtitle: "Bower Files Font Copy Failed!", - message: "Bower Files Font Copy Failed! Error: <%= error.message %>", - icon: __dirname + '/../icons/fail.png' - })(err); + gulp.task('bower-fonts', function () { + var onError = function (err) { + new notification().error(err, "Bower Files Font Copy Failed! Error: <%= error.message %>"); this.emit('end'); }; - + return gulp.src(bowerfiles({ - debugging: options.debugging, - filter: (/\.(eot|svg|ttf|woff|woff2|otf)$/i) - })) - .on('error', onError) - .pipe(changed(options.font.output)) - .pipe(gulp.dest(options.font.output)) - .pipe(new notification('Font Bower Files Imported!')); + debugging: options.debugging, + filter: options.font.filter + })) + .on('error', onError) + .pipe(ignore.exclude(isInline)) // Exclude inlined images + .pipe(changed(options.font.output)) + .pipe(gulp.dest(options.font.output)) + .pipe(new notification('Font Bower Files Imported!')); }); gulp.task('bower-imgs', function () { var onError = function (err) { - - notify.onError({ - title: "Laravel Elixir", - subtitle: "Bower Files Images Copy Failed!", - message: "Bower Files Images Copy Failed! Error: <%= error.message %>", - icon: __dirname + '/../icons/fail.png' - })(err); - + new notification().error(err, "Bower Files Images Copy Failed! Error: <%= error.message %>"); this.emit('end'); }; - var isInline = function (file) { - - var fsize = file.stat ? filesize(file.stat.size) : filesize(Buffer.byteLength(String(file.contents))); - var fext = file.path.split('.').pop(); - - if (options.debugging) - { - console.log("Size of file:" + file.path + " (" + 1024*parseFloat(fsize) +" / max="+options.img.maxInlineSize+")"); - } - - return options.img.extInline.indexOf(fext) > -1 && 1024*parseFloat(fsize) < options.img.maxInlineSize; - } - return gulp.src(bowerfiles({ debugging: options.debugging, - filter: (/\.(png|bmp|gif|jpg|jpeg)$/i) - })) - .on('error', onError) - .pipe(ignore.exclude(isInline)) // Exclude inlined images - .pipe(changed(options.img.output)) - .pipe(gulp.dest(options.img.output)) - .pipe(new notification('Images Bower Files Imported!')); + filter: options.img.filter + })) + .on('error', onError) + .pipe(ignore.exclude(isInline)) // Exclude inlined images + .pipe(changed(options.img.output)) + .pipe(gulp.dest(options.img.output)) + .pipe(new notification('Images Bower Files Imported!')); }); From 23a1714f861e98b1399b0538ad4366c8fb37f19a Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Sun, 25 Oct 2015 23:24:20 +0100 Subject: [PATCH 28/36] [Add] assets structure management --- README.md | 32 ++++++++++++++++++++++++++++++++ index.js | 52 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b1916ff..27a21ea 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The default settings are the following : ```javascript { debugging: false, // Enable/Disable verbose output + flatten: true, // Enable/Disable flat asset structure css: { file: 'vendor.css', // Merged CSS file output: config.cssOutput // Elixir default css output folder (public/css) @@ -111,3 +112,34 @@ This example does the following: - copy all webfonts in a `public/fonts/` folder. - copy all gif or png images into `public/css` folder. - inline any of those images which are smaller than 32k. + +```javascript +elixir(function(mix) { + mix.bower({ + debugging: true, + flatten: false, + css: { + output: 'public/css' + }, + js: false, + font: { + output: 'public/fonts' + }, + img: { + output: 'public/imgs', + extInline: ['gif', 'png'], // Extensions to inline + maxInlineSize: 32 * 1024 // [kB] Inline as data uri images below specified size + // (use 0 to disable, max 32k on ie8) + } + }); +}); +``` +This example does the following: +- scan your bower files +- deactivate flat asset mode +- concat all css files in a `public/css/plugins.css` file +- skips js files +- copy all webfonts in a `public/fonts/{bower_package}/xxx` folder (according to bower package structure) +- copy all gif or png images into `public/imgs/{bower_package}/xxx` folder (according to bower package structure) +- inline any of those images which are smaller than 32k. + diff --git a/index.js b/index.js index 780bf38..036a1f7 100644 --- a/index.js +++ b/index.js @@ -26,10 +26,11 @@ elixir.extend('bower', function (options) { var options = _.merge({ debugging: false, + flatten: true, css: { minify: true, file: 'vendor.css', - extInline: ['gif', 'png' ], + extInline: ['gif', 'png'], maxInlineSize: 32 * 1024, //max 32k on ie8 output: config.css.outputFolder ? config.publicPath + '/' + config.css.outputFolder : config.publicPath + '/css' }, @@ -88,26 +89,42 @@ elixir.extend('bower', function (options) { return context.targetFile; } - var absolutePath = context.targetFile.split('?').shift(); + var targetPath = context.targetFile.split(/\?|#/).shift() - var p = ""; + if (options.flatten) + { + targetPath = targetPath.split('/').pop(); + } else + { + targetPath = path.relative(opts.base, context.sourceDir + '/' + targetPath); + } + + var absolutePath = path.relative(context.destinationDir, targetPath) if (absolutePath.match(options.font.filter)) - p = path.relative(context.destinationDir, process.cwd() + '/' + options.font.output + '/' + context.targetFile.split('/').pop()); + targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.font.output + '/' + targetPath); if (absolutePath.match(options.img.filter)) - p = path.relative(context.destinationDir, process.cwd() + '/' + options.img.output + '/' + context.targetFile.split('/').pop()); + targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.img.output + '/' + targetPath); if (process.platform === 'win32') - p = p.replace(/\\/g, '/'); + targetPath = targetPath.replace(/\\/g, '/'); + + if (opts.debugging) + { + console.log(context.targetFile + " -> " + targetPath); + } - return p; + return targetPath; }; + var opts = { + debugging: options.debugging + }; - return gulp.src(bowerfiles({debugging: options.debugging})) + return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) .pipe(filter('**/*.css')) .pipe(test(options.css.maxInlineSize > 0, base64({ @@ -121,6 +138,7 @@ elixir.extend('bower', function (options) { .pipe(gulp.dest(options.css.output)) .pipe(new notification('CSS Bower Files Imported!')); + }); gulp.task('bower-js', function () { @@ -130,7 +148,11 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(bowerfiles({debugging: options.debugging})) + var opts = { + debugging: options.debugging + }; + + return gulp.src(bowerfiles(opts)) .on('error', onError) .pipe(filter('**/*.js')) .pipe(concat(options.js.file)) @@ -147,10 +169,12 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(bowerfiles({ + var opts = { debugging: options.debugging, filter: options.font.filter - })) + }; + + return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) .pipe(ignore.exclude(isInline)) // Exclude inlined images .pipe(changed(options.font.output)) @@ -165,10 +189,12 @@ elixir.extend('bower', function (options) { this.emit('end'); }; - return gulp.src(bowerfiles({ + var opts = { debugging: options.debugging, filter: options.img.filter - })) + }; + + return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) .pipe(ignore.exclude(isInline)) // Exclude inlined images .pipe(changed(options.img.output)) From bdcc91dd9ab5b024960c8a1cf505e985bbe0a72b Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Mon, 9 Nov 2015 21:18:44 +0100 Subject: [PATCH 29/36] [Crr] handle font url query string --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 036a1f7..4e15030 100644 --- a/index.js +++ b/index.js @@ -89,8 +89,9 @@ elixir.extend('bower', function (options) { return context.targetFile; } - var targetPath = context.targetFile.split(/\?|#/).shift() - + var targetPath = context.targetFile.split(/\?|#/)[0]; + var targetQuery = context.targetFile.split(/\?/)[1]; + if (options.flatten) { targetPath = targetPath.split('/').pop(); @@ -115,7 +116,7 @@ elixir.extend('bower', function (options) { console.log(context.targetFile + " -> " + targetPath); } - return targetPath; + return targetPath + (targetQuery !== undefined ? '?' + targetQuery : ''); }; From 09049e86f3428a899c1c6dfd940fe8fe3c9bba48 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Sun, 6 Dec 2015 20:49:56 +0100 Subject: [PATCH 30/36] [Crr] Syntax --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4e15030..b3a9cc6 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ elixir.extend('bower', function (options) { targetPath = path.relative(opts.base, context.sourceDir + '/' + targetPath); } - var absolutePath = path.relative(context.destinationDir, targetPath) + var absolutePath = path.relative(context.destinationDir, targetPath); if (absolutePath.match(options.font.filter)) targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.font.output + '/' + targetPath); From 581b8d13409a05fbec218a93b1af569f2dd5571f Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Sun, 6 Dec 2015 20:51:10 +0100 Subject: [PATCH 31/36] [Crr] Syntax --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b3a9cc6..004e24d 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,7 @@ elixir.extend('bower', function (options) { console.log("Size of file:" + file.path + " (" + 1024 * parseFloat(fsize) + " / max=" + options.css.maxInlineSize + ")"); return options.css.extInline.indexOf(fext) > -1 && 1024 * parseFloat(fsize) < options.css.maxInlineSize; - } + }; gulp.task('bower-css', function () { @@ -131,7 +131,7 @@ elixir.extend('bower', function (options) { .pipe(test(options.css.maxInlineSize > 0, base64({ extensions: options.css.extInline, maxImageSize: options.css.maxInlineSize, // bytes - debug: options.debugging, + debug: options.debugging }))) .pipe(rewrite({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) .pipe(concat(options.css.file)) From d79a12c303a34b80cf6ffcb2539ac36cf24a096a Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 17 Dec 2015 20:40:55 +0100 Subject: [PATCH 32/36] [Add] Flatten structure mode [Upd] Automatic gulp-* plugin loading --- index.js | 49 +++++++++++++++++++++---------------------------- package.json | 3 ++- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 004e24d..cde774d 100644 --- a/index.js +++ b/index.js @@ -1,28 +1,21 @@ var gulp = require('gulp'); var bowerfiles = require('main-bower-files'); -var elixir = require('laravel-elixir'); -var filter = require('gulp-filter'); -var notify = require('gulp-notify'); -var minify = require('gulp-minify-css'); -var uglify = require('gulp-uglify'); -var concat = require('gulp-concat'); -var changed = require('gulp-changed'); -var base64 = require('gulp-base64'); -var test = require('gulp-if'); -var ignore = require('gulp-ignore'); -var rewrite = require('gulp-rewrite-css'); +var Elixir = require('laravel-elixir'); + var filesize = require('filesize'); var path = require('path'); var validator = require('validator'); var isAbsolute = require('is-absolute-url'); -var task = elixir.Task; -var config = elixir.config; -var notification = elixir.Notification; +var task = Elixir.Task; +var config = Elixir.config; +var notification = Elixir.Notification; +var $ = require('gulp-load-plugins')(); var _ = require('lodash'); + -elixir.extend('bower', function (options) { +Elixir.extend('bower', function (options) { var options = _.merge({ debugging: false, @@ -91,7 +84,7 @@ elixir.extend('bower', function (options) { var targetPath = context.targetFile.split(/\?|#/)[0]; var targetQuery = context.targetFile.split(/\?/)[1]; - + if (options.flatten) { targetPath = targetPath.split('/').pop(); @@ -127,15 +120,15 @@ elixir.extend('bower', function (options) { return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) - .pipe(filter('**/*.css')) - .pipe(test(options.css.maxInlineSize > 0, base64({ + .pipe($.filter('**/*.css')) + .pipe($.if(options.css.maxInlineSize > 0, $.base64({ extensions: options.css.extInline, maxImageSize: options.css.maxInlineSize, // bytes debug: options.debugging }))) - .pipe(rewrite({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) - .pipe(concat(options.css.file)) - .pipe(test(options.css.minify, minify())) + .pipe($.rewritecss({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) + .pipe($.concat(options.css.file)) + .pipe($.if(options.css.minify, minify())) .pipe(gulp.dest(options.css.output)) .pipe(new notification('CSS Bower Files Imported!')); @@ -155,9 +148,9 @@ elixir.extend('bower', function (options) { return gulp.src(bowerfiles(opts)) .on('error', onError) - .pipe(filter('**/*.js')) - .pipe(concat(options.js.file)) - .pipe(test(options.js.uglify, uglify())) + .pipe($.filter('**/*.js')) + .pipe($.concat(options.js.file)) + .pipe($.if(options.js.uglify, uglify())) .pipe(gulp.dest(options.js.output)) .pipe(new notification('Javascript Bower Files Imported!')); @@ -177,8 +170,8 @@ elixir.extend('bower', function (options) { return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) - .pipe(ignore.exclude(isInline)) // Exclude inlined images - .pipe(changed(options.font.output)) + .pipe($.ignore.exclude(isInline)) // Exclude inlined images + .pipe($.changed(options.font.output)) .pipe(gulp.dest(options.font.output)) .pipe(new notification('Font Bower Files Imported!')); }); @@ -197,8 +190,8 @@ elixir.extend('bower', function (options) { return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) - .pipe(ignore.exclude(isInline)) // Exclude inlined images - .pipe(changed(options.img.output)) + .pipe($.ignore.exclude(isInline)) // Exclude inlined images + .pipe($.changed(options.img.output)) .pipe(gulp.dest(options.img.output)) .pipe(new notification('Images Bower Files Imported!')); diff --git a/package.json b/package.json index 51550e9..36adc0b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "gulp-rewrite-css":"^0.0", "filesize":"^2.0", "validator": "^4.2", - "is-absolute-url":"^2.0" + "is-absolute-url":"^2.0", + "gulp-load-plugins": "^1.0.0-rc.1" }, "peerDependencies":{ From 66c2ea79ceeedec61ff2176b697b6a8a0e2dd9d3 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 17 Dec 2015 20:40:55 +0100 Subject: [PATCH 33/36] [Add] Flatten structure mode [Upd] Automatic gulp-* plugin loading --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36adc0b..457156f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "laravel-elixir-bower", - "version": "1.0.0", + "version": "1.1.0", "description": "Laravel Elixir Bower Extension", "main": "index.js", "scripts": { From ea1b34df37f638c62d7713574d07ceb82f8a2955 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Thu, 17 Dec 2015 20:40:55 +0100 Subject: [PATCH 34/36] [Add] Flatten structure mode [Upd] Automatic gulp-* plugin loading --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cde774d..7b280eb 100644 --- a/index.js +++ b/index.js @@ -150,7 +150,7 @@ Elixir.extend('bower', function (options) { .on('error', onError) .pipe($.filter('**/*.js')) .pipe($.concat(options.js.file)) - .pipe($.if(options.js.uglify, uglify())) + .pipe($.if(options.js.uglify, $.uglify())) .pipe(gulp.dest(options.js.output)) .pipe(new notification('Javascript Bower Files Imported!')); From 7e59cd072547e5533b75f653a06423c26aa073c1 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Sat, 9 Jan 2016 14:31:14 +0100 Subject: [PATCH 35/36] [Add] Cssnano for css [Add] beautify for js --- index.js | 6 +++--- package.json | 40 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 7b280eb..8400ed9 100644 --- a/index.js +++ b/index.js @@ -126,9 +126,9 @@ Elixir.extend('bower', function (options) { maxImageSize: options.css.maxInlineSize, // bytes debug: options.debugging }))) - .pipe($.rewritecss({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) + .pipe($.rewriteCss({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) .pipe($.concat(options.css.file)) - .pipe($.if(options.css.minify, minify())) + .pipe($.if(options.css.minify, $.cssnano())) .pipe(gulp.dest(options.css.output)) .pipe(new notification('CSS Bower Files Imported!')); @@ -150,7 +150,7 @@ Elixir.extend('bower', function (options) { .on('error', onError) .pipe($.filter('**/*.js')) .pipe($.concat(options.js.file)) - .pipe($.if(options.js.uglify, $.uglify())) + .pipe($.if(options.js.uglify, $.uglify(),$.beautify())) .pipe(gulp.dest(options.js.output)) .pipe(new notification('Javascript Bower Files Imported!')); diff --git a/package.json b/package.json index 457156f..0c189bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "laravel-elixir-bower", - "version": "1.1.0", + "version": "1.2.0", "description": "Laravel Elixir Bower Extension", "main": "index.js", "scripts": { @@ -23,26 +23,28 @@ "url": "https://github.com/Crinsane/laravel-elixir-bower/issues" }, "dependencies": { - "gulp-changed": "^1.1", - "gulp-concat": "^2.4", - "gulp-filter": "^1.0", - "gulp-load-plugins": "^0.7", - "gulp-minify-css": "^0.3", - "gulp-notify": "^2.0", - "gulp-uglify": "^1.0", - "lodash": "^3.0", - "main-bower-files": "^2.1", - "gulp-base64" :"^0.1", - "gulp-if" :"^1.2", - "gulp-ignore" :"^1.2", - "gulp-rewrite-css":"^0.0", - "filesize":"^2.0", - "validator": "^4.2", - "is-absolute-url":"^2.0", - "gulp-load-plugins": "^1.0.0-rc.1" + "gulp-changed":"~1.1", + "gulp-concat":"~2.4", + "gulp-filter":"~1.0", + "gulp-load-plugins":"~0.7", + "gulp-minify-css":"~0.3", + "gulp-notify":"~2.0", + "gulp-uglify":"~1.0", + "gulp-beautify":"~1.0", + "gulp-cssnano":"~2.1.0", + "lodash":"~3.0", + "main-bower-files":"~2.1", + "gulp-base64" :"~0.1", + "gulp-if" :"~1.2", + "gulp-ignore" :"~1.2", + "gulp-rewrite-css":"~0.0", + "filesize":"~2.0", + "validator":"~4.2", + "is-absolute-url":"~2.0", + "gulp-load-plugins":"~1.0.0-rc.1" }, "peerDependencies":{ - "laravel-elixir":"^3.0" + "laravel-elixir": "~3.0" } } From dc8967b4cebb896a6321e2d1f8c6dc10b3efef49 Mon Sep 17 00:00:00 2001 From: Thomas GERVAIS Date: Fri, 22 Apr 2016 23:15:02 +0200 Subject: [PATCH 36/36] [Upd] dependencies [Upd] git ignore [Upd] using standardized elixir configuration --- .gitignore | 2 ++ index.js | 72 +++++++++++++++++++++--------------------- package.json | 88 +++++++++++++++++++++++++--------------------------- 3 files changed, 82 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index 1fe1b00..41ccd3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ node_modules/ +/nbproject/private/ +/nbproject/ diff --git a/index.js b/index.js index 8400ed9..19beb49 100644 --- a/index.js +++ b/index.js @@ -13,31 +13,31 @@ var notification = Elixir.Notification; var $ = require('gulp-load-plugins')(); var _ = require('lodash'); - + Elixir.extend('bower', function (options) { var options = _.merge({ - debugging: false, + debugging: !config.production, flatten: true, css: { - minify: true, - file: 'vendor.css', + minify: config.production, + outputFile: 'vendor.css', extInline: ['gif', 'png'], maxInlineSize: 32 * 1024, //max 32k on ie8 - output: config.css.outputFolder ? config.publicPath + '/' + config.css.outputFolder : config.publicPath + '/css' + outputFolder: config.get("public.css.outputFolder") }, js: { - uglify: true, - file: 'vendor.js', - output: config.js.outputFolder ? config.publicPath + '/' + config.js.outputFolder : config.publicPath + '/js' + uglify: config.production, + outputFile: 'vendor.js', + outputFolder: config.get("public.js.outputFolder") }, - font: { - output: (config.font && config.font.outputFolder) ? config.publicPath + '/' + config.font.outputFolder : config.publicPath + '/fonts', + fonts: { + outputFolder: config.get("public.fonts.outputFolder"), filter: /\.(eot|svg|ttf|woff|woff2|otf)$/i }, - img: { - output: (config.img && config.img.outputFolder) ? config.publicPath + '/' + config.img.outputFolder : config.publicPath + '/imgs', + images: { + outputFolder: config.get("public.images.outputFolder"), filter: /\.(png|bmp|gif|jpg|jpeg)$/i } @@ -49,9 +49,9 @@ Elixir.extend('bower', function (options) { files.push('bower-css'); if (options.js !== false) files.push('bower-js'); - if (options.font !== false) + if (options.fonts !== false) files.push('bower-fonts'); - if (options.img !== false) + if (options.images !== false) files.push('bower-imgs'); new task('bower', function () { @@ -95,11 +95,11 @@ Elixir.extend('bower', function (options) { var absolutePath = path.relative(context.destinationDir, targetPath); - if (absolutePath.match(options.font.filter)) - targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.font.output + '/' + targetPath); + if (absolutePath.match(options.fonts.filter)) + targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.fonts.outputFolder + '/' + targetPath); - if (absolutePath.match(options.img.filter)) - targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.img.output + '/' + targetPath); + if (absolutePath.match(options.images.filter)) + targetPath = path.relative(context.destinationDir, process.cwd() + '/' + options.images.outputFolder + '/' + targetPath); if (process.platform === 'win32') targetPath = targetPath.replace(/\\/g, '/'); @@ -114,22 +114,23 @@ Elixir.extend('bower', function (options) { }; var opts = { - debugging: options.debugging + debugging: options.debugging, + filter: '**/*.css' }; return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) - .pipe($.filter('**/*.css')) + //.pipe($.filter('**/*.css')) .pipe($.if(options.css.maxInlineSize > 0, $.base64({ extensions: options.css.extInline, - maxImageSize: options.css.maxInlineSize, // bytes + maxImageSize: options.css.maxInlineSize, // bytes debug: options.debugging }))) - .pipe($.rewriteCss({destination: options.css.output, debug: options.debugging, adaptPath: rebase})) - .pipe($.concat(options.css.file)) + .pipe($.rewriteCss({destination: options.css.outputFolder, debug: options.debugging, adaptPath: rebase})) + .pipe($.concat(options.css.outputFile)) .pipe($.if(options.css.minify, $.cssnano())) - .pipe(gulp.dest(options.css.output)) + .pipe(gulp.dest(options.css.outputFolder)) .pipe(new notification('CSS Bower Files Imported!')); @@ -143,15 +144,16 @@ Elixir.extend('bower', function (options) { }; var opts = { - debugging: options.debugging + debugging: options.debugging, + filter: '**/*.js' }; return gulp.src(bowerfiles(opts)) .on('error', onError) - .pipe($.filter('**/*.js')) - .pipe($.concat(options.js.file)) - .pipe($.if(options.js.uglify, $.uglify(),$.beautify())) - .pipe(gulp.dest(options.js.output)) + //.pipe($.filter('**/*.js')) + .pipe($.concat(options.js.outputFile)) + .pipe($.if(options.js.uglify, $.uglify(), $.beautify())) + .pipe(gulp.dest(options.js.outputFolder)) .pipe(new notification('Javascript Bower Files Imported!')); }); @@ -165,14 +167,14 @@ Elixir.extend('bower', function (options) { var opts = { debugging: options.debugging, - filter: options.font.filter + filter: options.fonts.filter }; return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) .pipe($.ignore.exclude(isInline)) // Exclude inlined images - .pipe($.changed(options.font.output)) - .pipe(gulp.dest(options.font.output)) + .pipe($.changed(options.fonts.outputFolder)) + .pipe(gulp.dest(options.fonts.outputFolder)) .pipe(new notification('Font Bower Files Imported!')); }); @@ -185,14 +187,14 @@ Elixir.extend('bower', function (options) { var opts = { debugging: options.debugging, - filter: options.img.filter + filter: options.images.filter }; return gulp.src(bowerfiles(opts), options.flatten ? null : {base: opts.base}) .on('error', onError) .pipe($.ignore.exclude(isInline)) // Exclude inlined images - .pipe($.changed(options.img.output)) - .pipe(gulp.dest(options.img.output)) + .pipe($.changed(options.images.outputFolder)) + .pipe(gulp.dest(options.images.outputFolder)) .pipe(new notification('Images Bower Files Imported!')); }); diff --git a/package.json b/package.json index 0c189bd..24c4390 100644 --- a/package.json +++ b/package.json @@ -1,50 +1,48 @@ { - "name": "laravel-elixir-bower", - "version": "1.2.0", - "description": "Laravel Elixir Bower Extension", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "laravel", - "elixir", - "bower", - "gulp" - ], - "repository": { - "type": "git", - "url": "https://github.com/Crinsane/laravel-elixir-bower" - }, - "author": "Rob Gloudemans", - "license": "MIT", - "homepage": "https://github.com/Crinsane/laravel-elixir-bower", - "bugs": { - "url": "https://github.com/Crinsane/laravel-elixir-bower/issues" - }, - "dependencies": { - "gulp-changed":"~1.1", - "gulp-concat":"~2.4", - "gulp-filter":"~1.0", - "gulp-load-plugins":"~0.7", - "gulp-minify-css":"~0.3", - "gulp-notify":"~2.0", - "gulp-uglify":"~1.0", - "gulp-beautify":"~1.0", - "gulp-cssnano":"~2.1.0", - "lodash":"~3.0", - "main-bower-files":"~2.1", - "gulp-base64" :"~0.1", - "gulp-if" :"~1.2", - "gulp-ignore" :"~1.2", - "gulp-rewrite-css":"~0.0", - "filesize":"~2.0", - "validator":"~4.2", - "is-absolute-url":"~2.0", - "gulp-load-plugins":"~1.0.0-rc.1" - + "name": "laravel-elixir-bower", + "version": "1.2.3", + "description": "Laravel Elixir Bower Extension", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "laravel", + "elixir", + "bower", + "gulp" + ], + "repository": { + "type": "git", + "url": "https://github.com/Crinsane/laravel-elixir-bower" + }, + "author": "Rob Gloudemans", + "license": "MIT", + "homepage": "https://github.com/Crinsane/laravel-elixir-bower", + "bugs": { + "url": "https://github.com/Crinsane/laravel-elixir-bower/issues" + }, + "dependencies": { + "filesize": "~3.3.0", + "gulp-base64": "~0.1", + "gulp-beautify": "~2.0", + "gulp-changed": "~1.1", + "gulp-concat": "~2.4", + "gulp-cssnano": "~2.1.0", + "gulp-filter": "~1.0", + "gulp-if": "~1.2", + "gulp-ignore": "~1.2", + "gulp-load-plugins": "~1.2.2", + "gulp-minify-css": "~0.3", + "gulp-notify": "~2.0", + "gulp-rewrite-css": "~0.0", + "gulp-uglify": "~1.0", + "is-absolute-url": "~2.0", + "lodash": "~3.0", + "main-bower-files": "~2.11", + "validator": "~4.2" }, "peerDependencies":{ - "laravel-elixir": "~3.0" + "laravel-elixir": ">3.0" } }