3 ms·
I've written about JS modules in the past. https://medium.com/what-i-learned-building/5a31feb15e2 https://medium.com/what-i-learned-building/5a31feb15e2 While
by wyuenho 13y ago
I've written about JS modules in the past.
https://medium.com/what-i-learned-building/5a31feb15e2 https://medium.com/what-i-learned-building/5a31feb15e2
While I think OP's link is quite informative, I think it suffers from the same oversight as most others on this topic has - confusing JS modules with Web components.
The JS world is split in 2 right now - client and server - for good reason because they are 2 very different domains with very different requirements. While a node package will work just fine by itself on the server, reusable code written for the browser usually doesn't work on its own. Some will require the window/document/location/whatever host object to be present, while others, mostly UI components, have to rely on other things like CSS and some minimal markup to work. Guess what? Most reusable browser code is NOT a JS module, they are Web components. As such, no pure JS solution with solve the dependency management problem on the browser. A proper solution must be able to package up different kinds of resources that constitute a whole Web component nicely for consumption. Having the One True Way to manage JS dependency is just a small part of it, in which any solution will do (tho I agree with the article OP linked to suggests, CommonJS style is the more tasteful choice for now before ES6 lands).
As far as I know, Browserify, Ender and Bower fail at the above totally, utterly, completely. Only Component and Volo seem to be on the right track as the moment I think.
- fragmede 13y ago> The JS world is split in 2 right now What about Meteor?
- Bockit 13y agoWhat do you think of browserify coupled with transforms providing html templates[1] and css inclusion[2]. [1]: E.g., https://npmjs.org/package/browserify-jade https://npmjs.org/package/browserify-jade [2]: E.g., https://npmjs.org/package/stylify https://npmjs.org/package/stylify
- wyuenho 13y agopackage.json doesn't have any place to define the styles and templates your component exports, so browserify can't meaningfully resolve dependencies and build your assets for you. For really good support, you'll need to be able to rewrite the URLs inside CSS too due to different directory structures within each component. Component does that for you.
- Bockit 13y agoThat's a pretty fair point about the CSS url rewriting, it's possibly the kind of thing you can fix with a browserify transform, but iffy and as you say component is doing it already.