Skip to content

Commit

Permalink
Merge pull request #236 from silvenon/bower
Browse files Browse the repository at this point in the history
Remove ../'s from bower_components paths
  • Loading branch information
sindresorhus committed Dec 19, 2014
2 parents bb6070f + 64cf7be commit c32e765
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ To install dependencies, run `bower install --save package-name` to get the file

## Docs

We have [recipes](docs/recipes/README.md) for integrating other popular technologies like CoffeeScript.
* [recipes](docs/recipes/README.md) for integrating other popular technologies like CoffeeScript
* [details](docs/bower.md) about our Bower setup


## Options
Expand Down
4 changes: 3 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module.exports = yeoman.generators.Base.extend({

// wire Bootstrap plugins
if (this.includeBootstrap) {
var bs = '../bower_components/';
var bs = 'bower_components/';

if (this.includeSass) {
bs += 'bootstrap-sass-official/assets/javascripts/bootstrap/';
Expand Down Expand Up @@ -217,6 +217,7 @@ module.exports = yeoman.generators.Base.extend({
bowerJson: bowerJson,
directory: 'bower_components',
exclude: ['bootstrap-sass', 'bootstrap.js'],
ignorePath: /^(\.\.\/)+/,
src: 'app/index.html'
});

Expand All @@ -225,6 +226,7 @@ module.exports = yeoman.generators.Base.extend({
wiredep({
bowerJson: bowerJson,
directory: 'bower_components',
ignorePath: /^(\.\.\/)+/,
src: 'app/styles/*.scss'
});
}
Expand Down
16 changes: 10 additions & 6 deletions app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gulp.task('styles', function () {<% if (includeSass) { %>
return gulp.src('app/styles/main.scss')
.pipe($.rubySass({
style: 'expanded',
precision: 10
precision: 10,
loadPath: ['.']
}))
.on('error', function (err) { console.log(err.message); })<% } else { %>
return gulp.src('app/styles/main.css')<% } %>
Expand All @@ -26,7 +27,7 @@ gulp.task('jshint', function () {
});

gulp.task('html', ['styles'], function () {
var assets = $.useref.assets({searchPath: '{.tmp,app}'});
var assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});

return gulp.src('app/*.html')
.pipe(assets)
Expand Down Expand Up @@ -74,8 +75,6 @@ gulp.task('connect', ['styles', 'fonts'], function () {
.use(require('connect-livereload')({port: 35729}))
.use(serveStatic('.tmp'))
.use(serveStatic('app'))
// paths to bower_components should be relative to the current file
// e.g. in app/index.html you should use ../bower_components
.use('/bower_components', serveStatic('bower_components'))
.use(serveIndex('app'));

Expand All @@ -95,11 +94,16 @@ gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
<% if (includeSass) { %>
gulp.src('app/styles/*.scss')
.pipe(wiredep())
.pipe(wiredep({
ignorePath: /^(\.\.\/)+/
}))
.pipe(gulp.dest('app/styles'));
<% } %>
gulp.src('app/*.html')
.pipe(wiredep(<% if (includeSass && includeBootstrap) { %>{exclude: ['bootstrap-sass-official']}<% } %>))
.pipe(wiredep({<% if (includeSass && includeBootstrap) { %>
exclude: ['bootstrap-sass-official'],<% } %>
ignorePath: /^(\.\.\/)*\.\./
}))
.pipe(gulp.dest('app'));
});

Expand Down
2 changes: 1 addition & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- endbuild -->
<% if (includeModernizr) { %>
<!-- build:js scripts/vendor/modernizr.js -->
<script src="../bower_components/modernizr/modernizr.js"></script>
<script src="bower_components/modernizr/modernizr.js"></script>
<!-- endbuild --><% } %>
</head>
<body>
Expand Down
17 changes: 17 additions & 0 deletions docs/bower.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Bower components

We moved `bower_components` to the project root, read [this post](http://yeoman.io/blog/bower_components-in-project-root.html) if you're curious why. In order for that to work, we had to make some accommodations. If you're ever have struggles with it, this should clear things up.

Basically:

* paths in Sass `@import` directives should begin with `bower_components`
* paths in HTML should begin with `/bower_components`

Both paths will work regardless of the nesting level, e.g. they would work on a `about/contact/index.html` page too.

Details:

* we serve `bower_components` as if it is located in `app`
* we add the project root to Sass load path in order for `@import "bower_components/..."` directives to work
* we strip all the `../`s from the beginning of `bower_components` paths
* we add the project root to [gulp-useref](https://github.com/jonkemp/gulp-useref)'s search path in order for the build step to work

0 comments on commit c32e765

Please sign in to comment.