Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CSS imports correctly #138

Closed
jhnns opened this issue Aug 3, 2015 · 8 comments
Closed

Handle CSS imports correctly #138

jhnns opened this issue Aug 3, 2015 · 8 comments

Comments

@jhnns
Copy link
Member

jhnns commented Aug 3, 2015

node-sass treats CSS imports this way:

If a file ending is provided...

...the import statement stays untouched, but the file contents are not included:

@import "./some-css-module.css";

becomes

@import url(./some-css-module.css);

If no file ending is provided...

...it is treated as scss and included.

The sass-loader should treat it the same way. Currently the sass-loader outputs an absolute path to the CSS file which is pretty useless.

@jorrit
Copy link
Contributor

jorrit commented Aug 3, 2015

What is the webpack.config.js in your case? Does extensions contain the empty string?

@rlucha
Copy link

rlucha commented Aug 4, 2015

+1 same here

@jsg2021
Copy link

jsg2021 commented Aug 4, 2015

Yep, this is what I was talking about in #101

Just a reminder, the css file cannot be just treated as scss... the url refs in the css file should be relative to that css file.

@jsg2021
Copy link

jsg2021 commented Aug 4, 2015

after looking into how sass does things, i actually am starting to think the behavior just needs to make sure the compiled sass has what the css/style loader needs to consume those references.

In webpack, is it the loader's responsibility to offer new imports to webpack to consume? or should the piped output from the sass loader into css-loader be sufficient?

jhnns added a commit that referenced this issue Aug 4, 2015
#138

New algorithm:

- Imports with no file extension:
  - Prefer modules starting with '_'
  - File extension precedence: .scss, .sass, .css
- Imports with file extension:
  - If the file is a CSS-file, do not include it all
  - The exact file name must match

This is how node-sass does it.
@jhnns
Copy link
Member Author

jhnns commented Aug 5, 2015

Could you check out the current master branch and check if it works for you? I've heavily refactored the import mechanism and need more tests.

@jhnns
Copy link
Member Author

jhnns commented Aug 6, 2015

Fixed with 2.0.0

@jhnns jhnns closed this as completed Aug 6, 2015
@jsg2021
Copy link

jsg2021 commented Aug 6, 2015

It looks like the CSS content is being interpreted as SCSS and using the same 'pwd' (for lack of a better term)

so a fonts css file with the content below looks at the main SCSS's path instead of the imported CSS's path and icomoon.woff/svg files get the lovely Cannot resolve 'file' or 'directory' ./icomoon.woff in /Users/jgrimes/Workspace/nti.web.mobile/src/main/resources/scss ...when the file is actually not under that scss directory and is under ../fonts/icomoon/ which is where the css file is.

@font-face {
    font-family: 'icomoon';
    src: url(icomoon.woff) format('woff'),
        url(icomoon.svg) format('svg');
    font-weight: normal;
    font-style: normal;
}

@jsg2021
Copy link

jsg2021 commented Aug 6, 2015

Oh, wait... leaving the .css extension on the import, webpack is now correctly handling them. Sweet. :) looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants