thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
933 stars 87 forks source link

Get bower_components path from .bowerrc? #108

Closed KingScooty closed 9 years ago

KingScooty commented 9 years ago

Is there a way to grab the root path to the /bower_components directory by looking for a .bowerrc file in the base directory?

I have different locations for my bower components depending on the project, and will typically specify the path in a .bowerrc file.

This would make referencing bower components so much more attractive as the repetition of paths relative to the package.json gets rather tiring and cumbersome.

bendrucker commented 9 years ago

You can do this more easily by providing your own shim file. You can parse .bowerrc and prepend paths there in code.

KingScooty commented 9 years ago

Sounds promising, although it still seems a little messy. Any ideas how i can tidy this up a bit more?

var fs = require('fs'),
    path = require("path");

var bowerrc = JSON.parse(fs.readFileSync(path.join(__dirname, '../', '.bowerrc')));

var jquery = bowerrc + 'jquery/dist/jquery.js',
    modernizr = bowerrc + 'modernizr/modernizr.js'

module.exports = {
  jquery    : { 'exports': '$' },
  modernizr : { 'exports': 'Modernizr' }
}
bendrucker commented 9 years ago

Did you miss something while copying and pasting? That code does nothing.

KingScooty commented 9 years ago

That's my shim file, which package.json imports. Seems to be working for me, but it feels rather bloated when all i really want to do is prefix paths for bower_components.

bendrucker commented 9 years ago

Well you must have something going on somewhere else, maybe in the browser field? You're doing all that stuff and then never doing anything with the variables. I don't think there's really a compelling reason to offer a special base path for shimmed components. And per your original request, reading from bowerrc is definitely outside the scope of browserify-shim.