rotundasoftware / parcelify

Add css to your npm modules consumed with browserify.
MIT License
251 stars 20 forks source link

Parcelify for css only modules? #28

Closed bcomnes closed 9 years ago

bcomnes commented 9 years ago

I'm trying to understand how to set up a package.json for a css reset module that isn't associated with any requireable javascript, and allow it to be consumed by parcelify.

I have a "style": "dist/sanitize.css", field, but have omitted a main field and have no index.js/json. There is a gulp file which is used to build the consumable css file and is specified through npm scripts. It just didn't seem like there is a use for a main field in this case. Will this be enough for parcelify to use this module in a bundle somehow?

dgbeck commented 9 years ago

Hi @bcomnes, to get it to compile with parcelify using vanilla css you'll need an empty "index.js" file, and to require that file via javascript. i.e

require( 'my-css-module' )

where you have an empty js file in

node_modules/my-css-module/index.js

It is not the most straight forward approach for this use case but it follows naturally from parcelify's paradigm of keeping the dependency graph just in javascript instead of having parallel graphs for each asset type. Two other approaches are

  1. To simply include the css file in the page being rendered with a standard <style> tag
  2. Use sass or less to do include the reset css. If you want the reset css in a separate node module, you can use parcelify-import-resolver as described in the docs of that repo.

Hope that helps. Closing for now, let us know if that does not resolve your issue.

bcomnes commented 9 years ago

Cool! Makes total sense. Still trying to understand the state of npm + css and this is a very cool approach!