brunch / deppack

Extract node modules to browser.
MIT License
4 stars 13 forks source link

requiring relative css file doesn't work #9

Closed marcioj closed 8 years ago

marcioj commented 8 years ago

I was trying to use the css-brunch plugin but using require('./styles.css') shows the following error

03 Apr 22:36:26 - error: Resolving deps of app/initialize.js failed. Could not load module 'styles.css' from '/home/marcio/workspace/javascript/test-brunch/app'. Possible solution: add 'styles.css' to package.json and `npm install`

Using require with js files works fine.

Diving into the code I found out that this problem might be related with the following lines here

deps = allDeps.map(d => helpers.isRelative(d) ? sysPath.relative('.', sysPath.resolve(sysPath.dirname(nameCleaner(path)), d)) : d);

When computing the dependencies from initialize.js file, the allDeps variable changes from ['./styles.css'] to ['styles.css']. Afterward this array is passed to browser-resolve which throws the error. I changed the code manually to preserve the ['./styles.css'] behavior and everything worked fine. But it's not clear to me what this line is suppose to do. So I'm opening an issue here, since this looks like a bug.

paulmillr commented 8 years ago

require('./styles') should work, without extension

paulmillr commented 8 years ago

Also make sure you have css: {modules: true}

marcioj commented 8 years ago

require('./styles') should work, without extension

This worked, thanks!

Maybe the css-brunch README should be updated to reflect this. Right now this is the current example:

var style = require('./title.css');

<h1 className={style.title}>Yo</h1>
goshacmd commented 8 years ago

Still, extensions kind of should be working... I'll look into it

goshacmd commented 8 years ago

Ok, created https://github.com/brunch/deppack/pull/12 to address that. Thanks for the report!