browser field spec for package.json (original) (raw)
It is not completely related to this, but i want to extend the concept of client side (only) libraries npm. Imo the problem of client side dependencies with js, css, etc. is still not solved yet. There are tools for some parts of it but no common specification or configuration etc. What about other client side assets like css, less or images? At the moment thats completely missing in my opinion.
There is already the directories
property in the CommonJS spec, but it is missing keys for static assets like css, less, images, etc. (http://wiki.commonjs.org/wiki/Packages/1.0#Optional_Fields and https://www.npmjs.org/doc/files/package.json.html#directories)
There are tons of great client side libraries on npm but every single one is different to use / consume in the frontend when it comes to css, less, sass, images, fonts, etc. How to include them? What files should be included? In which order? It would be great if package maintainers could clearly describe what additional assets, besides javascript are shipped with the npm package and how to consume them.
Lets take bootstrap as an example (original https://github.com/twbs/bootstrap/blob/master/package.json)
Why not?
{
"name": "bootstrap",
"description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
"version": "3.3.0",
"homepage": "http://getbootstrap.com",
"author": "Twitter, Inc.",
"scripts": {
"test": "grunt test"
},
"directories": {
"assets": {
"css": ["dist/css/bootstrap.min.css","dist/css/bootstrap-theme.min.css"],
"js":["dist/js/bootstrap.min.js"]
"font":["dist/fonts/glyphicons-halflings-regular.eot","dist/fonts/glyphicons-halflings-regular.eot","dist/fonts/glyphicons-halflings-regular.svg","dist/fonts/glyphicons-halflings-regular.ttf", "dist/fonts/glyphicons-halflings-regular.woff"]
}
},
"main": "./dist/js/npm",
"repository": {
"type": "git",
"url": "https://github.com/twbs/bootstrap.git"
},
"bugs": {
"url": "https://github.com/twbs/bootstrap/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/twbs/bootstrap/blob/master/LICENSE"
},
"jspm": {
"main": "js/bootstrap",
"directories": {
"example": "examples",
"lib": "dist"
},
"shim": {
"js/bootstrap": {
"imports": "jquery",
"exports": "$"
}
},
"buildConfig": {
"uglify": true
}
}
}
This could be even further extended to configure which assets are already "compiled", minified or packaged for usage or which assets are optional (bootstrap-theme.min.css).
Here are some very popular packages with js, css and/or other assets on npm without any further configuration:
- https://github.com/angular-ui/bootstrap/blob/master/package.json
- https://github.com/angular/angular.js/blob/master/package.json
- https://github.com/jquery/jquery/blob/master/package.json
- https://github.com/ivaynberg/select2/blob/master/package.json
- https://github.com/jquery/jquery-ui/blob/master/package.json
- https://github.com/DataTables/DataTables/blob/master/package.json
- https://github.com/ExactTarget/fuelux/blob/master/package.json
- https://github.com/react-bootstrap/react-bootstrap/blob/master/package.json
- https://github.com/facebook/react/blob/master/package.json
Package Managers like bower, component, npm or other tools like browserify, etc. could use this information only or in addition to their separate configuration files.
What do you think?
cheers