We are both blessed and cursed by a plethora of package management solutions for JavaScript, all with their respective merits. For reasons that are irrelevant here, I have settled on npm for my primary solution. However, there is too much good code out there on other systems like bower and component to ignore these solutions. So, I am looking to set up an environment where I can use browserify to load packages from both npm and bower (we'll save component for another question).
The best I came up with so far was to setup my package.json
with a postinstall
script that runs bower install
:
{
... configuration ...
"scripts": {
"postinstall": "bower install"
}
}
This builds the correct directory structure when installing first-level dependencies (i.e. strait bower dependencies and strait npm dependencies):
- MyMixedComponent
- main.js
- package.json
- node_modules
- npmDependency
- bower_components
- bowerComponent
Which builds fine using the debowerify transform on browserify, browserify -t debowerify
However, when I want to then install MyMixedComponent from npm in another project, npm install MyMixedComponent
, the directory structure is built as you would expect from npm:
- MyNewProject
- main.js
- package.json
- node_modules
- MyMixedComponent
- main.js
- package.json
- node_modules
- npmDependency
- bower_components
- bowerComponent
Since bower is a flat dependency tree, this of course does not work when trying to build with browserify and debowerify. Whats actually needed is something like this:
- MyNewProject
- main.js
- package.json
- node_modules
- MyMixedComponent
- main.js
- package.json
- node_modules
- npmDependency
- bower_components
- bowerComponent
Alternatively debowerify could be modified to recognize multiple bower directories, but that would defeat the lovely characteristic of bower that it is a flat tree, which is much better for front end dependencies. Any thoughts about how this could work, or should I just pray that we all someday agree on dependency management?
The idea of having multiple bower_components in the same codebase, has the risk of introducing duplicates of some particular framework.
Try going down the road of :
bower install
into root of current packageIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With