Node-sass: sass middleware requires css and sass files to have the same directory structure

Created on 15 Jan 2014  路  15Comments  路  Source: sass/node-sass

if I request "/stylesheets/foo.css" and point the middle ware at a folder called "sass" my sass file needs to be "sass/stylesheets/foo.scss"

Most helpful comment

I agree -- it would be preferable to allow separate directories for sass files vs. css output.

All 15 comments

I'm sorry, I'm not sure what you mean, can you give an example?

I finally traced it down, My request was for /stylesheets/whatever.css so node-sass forces me to put my sass file in /sass/stylesheets/whatever.scss, not sure that it's a bug, but it is annoying and undocumented.

I agree -- it would be preferable to allow separate directories for sass files vs. css output.

+1 to separate directories for SASS and CSS.

I've narrowed it down to Lines 80-90 of lib/middleware.js. I'm not sure I have enough understanding of Connect vs Express middleware idioms to not screw anything up right now though.

@radfahrer Thanks for submitting this issue. I'm able to reproduce this locally so I will take a look at this ASAP.

var server = connect.createServer(
  sass.middleware({
    src: __dirname + '/public/sass',
    dest: __dirname + '/public/css',
    debug: true,
    outputStyle: 'compressed'
  }),
  connect.static(__dirname + '/public')
);

gives output:

source : /Users/adamyeats/Dropbox/Code/node-sass/examples/public/sass/css/test.scss
dest : /Users/adamyeats/Dropbox/Code/node-sass/examples/public/css/css/test.css
read : /Users/adamyeats/Dropbox/Code/node-sass/examples/public/css/css/test.css

Looks like this issue stems from the fact that, using my above code as an example, dest (a.k.a /public/css) is served at http://localhost:3000/ (so at the root URL). Requesting http://localhost:3000/css/styles.css would look to render the file at /public/css/css/test.css. This doesn't seem like expected behaviour to me, would one of the other maintainers be able to clarify? cc/ @andrew

@adamyeats the middleware was originally based on https://github.com/LearnBoost/stylus/blob/master/lib/middleware.js, which I seem to remember does the same behaviour, but it's been a good while since I've used it.

First of all, this is my first day with node-sass, so forgive me if I misunderstood the problem here. But I just fixed a similar problem for myself, and it seems that this issue, as well as https://github.com/andrew/node-sass/issues/197, are the same.

The problem here is that the code snipet of @adamyeats does not include a prefix option. By adding prefix: '/css' to the middleware options, the output becomes

  source : /Users/jkap/Projects/sass-test/public/sass/test.scss
  dest : /Users/jkap/Projects/sass-test/public/css/test.css
  read : /Users/jkap/Projects/sass-test/public/css/test.css

As a side note here, one can see that node-sass does support separate directories for CSS and SASS quite nicely (which apparently was the original request in this very issue).

The prefix option was not documented very well, and it took me a while to understand why middleware.js works the way it works. However, when the middleware request comes, the only thing middleware gets to know, is the request path (eg. /css/test.css), and based on this info only, it has to figure out if that is something it should react to. So what it does, is that is attaches this path to the CSS source directory path, and checks if a file can be read from the generated path.

If prefix is given and it is found at the beginning of path, only the remaining part of path is then used. After this "fix", concatenating the path to source and destination directories are starting to make more sense.

IMHO prefix option should have better documentation, and it could perhaps be re-named to be cssRequestPrefix or something else more clarifying.

@cido It would be great if you could put together some of your findings as a pull request to improve the documentation.

@andrew Yep, I was thinking the very same. I'll try to write something today.

I think I'm understanding that this is something taht can be fixed using one of the package options, but @cido, can you confirm? Also, if you can give an example setup and maybe @andrew wouldn't mind adding it to the README because right now it's a bit unclear.

@ilanbiala I tried to explain the situation as well as I could in my previous answer. I've been quite busy lately, but I am still planning to submit a PR for improving the documentation. Hopefully I can do it during the next couple of days. However, in the mean time, read my answer above one more time, add prefix option to the middleware options, and try to experiment with it. Hope you get it working.

The middleware in node-sass is totally gone with v2.0.0-beta and is moved to a separate repo: https://github.com/sass/node-sass-middleware. Please report this issue there, if it persists.

Was this page helpful?
0 / 5 - 0 ratings