Skip to content

Commit

Permalink
Add config options to allow consistent bundle file content ordering. F…
Browse files Browse the repository at this point in the history
…ixes #25
  • Loading branch information
chmontgomery committed Jul 17, 2015
1 parent e3578f5 commit 14a2a9c
Show file tree
Hide file tree
Showing 50 changed files with 301 additions and 6 deletions.
47 changes: 47 additions & 0 deletions examples/full/bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,53 @@ module.exports = {
rev: prodLikeEnvs,
maps: false // {(boolean)} disable sourcemaps
}
},
'ordered-bundle': {
scripts: [
{
src: './ordered_bundle/bower_components/jquery.js',
minSrc: './ordered_bundle/bower_components/jquery.min.js'
},
'./ordered_bundle/vendor/*.js',
'./ordered_bundle/content/*.coffee',
'./ordered_bundle/content/*.js'
],
styles: [
{
src: './ordered_bundle/bower_components/bootstrap.css',
minSrc: './ordered_bundle/bower_components/bootstrap.min.css'
},
'./ordered_bundle/vendor/*.css',
'./ordered_bundle/content/*.less',
'./ordered_bundle/content/*.css'
],
options: {
useMin: prodLikeEnvs,
order: {
scripts: [
'**/always-first.js', // from /content
'**/jquery*.js', // depending on env, this could be streaming min or non-min file so use trailing *
'**/lodash.js', // from /vendor
'**/file1.js', // compiled from file1.coffee
'**/file2.js', // compiled from file2.coffee
'!**/always-last.js', // everything else except always-last.js
'**/always-last.js' // from /content
],
styles: [
'**/always-first.css', // from /content
'**/bootstrap*.css', // depending on env, this could be streaming min or non-min file so use trailing *
'**/vendor.css', // from /vendor
'**/file1.css', // compiled from file1.less
'**/file2.css', // compiled from file2.less
'!**/always-last.css', // everything else except always-last.css
'**/always-last.css' // from /content
]
},
transforms: {
scripts: transformHelper.coffee(),
styles: transformHelper.less()
}
}
}
},
copy: [
Expand Down
4 changes: 4 additions & 0 deletions examples/full/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"main": {
"scripts": "<script src='/public/main-a2f0720d62.js' type='text/javascript'></script>",
"styles": "<link href='/public/main-56c9e7f7a2.css' media='all' rel='stylesheet' type='text/css'/>"
},
"ordered-bundle": {
"styles": "<link href='/public/ordered-bundle-421fc9b36f.css' media='all' rel='stylesheet' type='text/css'/>",
"scripts": "<script src='/public/ordered-bundle-cbd3c3edb4.js' type='text/javascript'></script>"
}
}
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/bower_components/bootstrap.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bootstrap {
background-color: orange;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.bootstrap-min {background-color: coral;}
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/bower_components/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("jquery");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("jquery.min");
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/content/always-first.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.always-first {
background-color: red;
}
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/content/always-first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("first");
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/content/always-last.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.always-last {
background-color: green;
}
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/content/always-last.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("last");
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/content/file1.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fileName = 'file1.coffee'
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/content/file1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.file1-less {
background-color: purple;
}
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/content/file2.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fileName = 'file2.coffee'
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/content/file2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.file2-less {
background-color: yellow;
}
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/content/for-the-middle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.something-in-the-middle {
background-color: blue;
}
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/content/for-the-middle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("something in the middle");
1 change: 1 addition & 0 deletions examples/full/ordered_bundle/vendor/lodash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("lodash");
3 changes: 3 additions & 0 deletions examples/full/ordered_bundle/vendor/vendor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vendor {
background-color: wheat;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/full/public/maps/ordered-bundle-cbd3c3edb4.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions examples/full/public/ordered-bundle-421fc9b36f.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions examples/full/public/ordered-bundle-cbd3c3edb4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions examples/guarantee-content-order/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Guarantee Bundle Content Order

The bundle config supports ordering the src files via `gulp-order` syntax (e.g. wildcards, etc). See here for details on syntax: https://github.com/sirlantis/gulp-order

To use simply add your ordering array to the `order` option:

```js
module.exports = {
bundle: {
main: {
scripts: [
{
src: './vendor/second.js',
minSrc: './vendor/second.min.js'
},
'./a/*.coffee',
'./content/**/*.coffee',
'./content/**/*.js'
]
options: {
order: {
scripts: [
'**/always-first.js', // from /content
'**/second*.js', // depending on env, this could be streaming min or non-min file so use trailing *
'**/third.js', // compiled from third.coffee
'**/fourth.js', // compiled from fourth.coffee
'!**/always-last.js', // everything else except always-last.js
'**/always-last.js' // from /content
]
},
transforms: {
scripts: transformHelper.coffee()
}
}
}
}
};

```

### Examples

* This example [`bundle.config.js`](bundle.config.js#L25)
* full example [`bundle.config.js`](../full/bundle.config.js#L155)
1 change: 1 addition & 0 deletions examples/guarantee-content-order/a/fourth.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fileName = 'fourth'
3 changes: 3 additions & 0 deletions examples/guarantee-content-order/a/fourth.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.fourth {
background-color: purple;
}
51 changes: 51 additions & 0 deletions examples/guarantee-content-order/bundle.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var transformHelper = require('../../index.js').transformHelper;

module.exports = {
bundle: {
'ordered-bundle': {
scripts: [
{
src: './vendor/second.js',
minSrc: './vendor/second.min.js'
},
'./a/*.coffee',
'./content/**/*.coffee',
'./content/**/*.js'
],
styles: [
{
src: './vendor/second.css',
minSrc: './vendor/second.min.css'
},
'./a/*.less',
'./content/**/*.less',
'./content/**/*.css'
],
options: {
order: {
scripts: [
'**/always-first.js', // from /content
'**/second*.js', // depending on env, this could be streaming min or non-min file so use trailing *
'**/third.js', // compiled from third.coffee
'**/fourth.js', // compiled from fourth.coffee
'!**/always-last.js', // everything else except always-last.js
'**/always-last.js' // from /content
],
styles: [
'**/always-first.css', // from /content
'**/second*.css', // depending on env, this could be streaming min or non-min file so use trailing *
'**/third.css', // compiled from third.less
'**/fourth.css', // compiled from fourth.less
'!**/always-last.css', // everything else except always-last.css
'**/always-last.css' // from /content
]
},
useMin: 'production',
transforms: {
scripts: transformHelper.coffee(),
styles: transformHelper.less()
}
}
}
}
};
3 changes: 3 additions & 0 deletions examples/guarantee-content-order/content/always-last.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.always-last {
background-color: green;
}
1 change: 1 addition & 0 deletions examples/guarantee-content-order/content/always-last.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('last');
3 changes: 3 additions & 0 deletions examples/guarantee-content-order/content/fifth.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.fifth {
background-color: blue;
}
1 change: 1 addition & 0 deletions examples/guarantee-content-order/content/fifth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('fifth');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.always-first {
background-color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('first');
1 change: 1 addition & 0 deletions examples/guarantee-content-order/content/third.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fileName = 'third'
3 changes: 3 additions & 0 deletions examples/guarantee-content-order/content/third.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.third {
background-color: yellow;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/guarantee-content-order/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var gulp = require('gulp'),
del = require('del'),
bundle = require('../../index');

gulp.task('bundle', ['clean'], function () {
return gulp.src('./bundle.config.js')
.pipe(bundle())
.pipe(gulp.dest('./dist'));
});

gulp.task('clean', function (cb) {
del([
'./dist'
], cb);
});

gulp.task('default', ['bundle']);
15 changes: 15 additions & 0 deletions examples/guarantee-content-order/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "guarantee-content-order",
"version": "1.0.0",
"description": "",
"main": "bundle.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"del": "^1.2.0",
"gulp": "^3.9.0"
}
}
3 changes: 3 additions & 0 deletions examples/guarantee-content-order/vendor/second.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.second {
background-color: orange;
}
1 change: 1 addition & 0 deletions examples/guarantee-content-order/vendor/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('second');
1 change: 1 addition & 0 deletions examples/guarantee-content-order/vendor/second.min.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.second-min {background-color: coral;}
1 change: 1 addition & 0 deletions examples/guarantee-content-order/vendor/second.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('second.min');
1 change: 1 addition & 0 deletions lib/init-option-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = function (bundle) {
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-minify-css'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-minify-css'] || {};
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-uglify'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-uglify'] || {};
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-concat'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-concat'] || {};
bundle[BundleKeys.OPTIONS].order = bundle[BundleKeys.OPTIONS].order || {};
};
Loading

0 comments on commit 14a2a9c

Please sign in to comment.