edited for the ilollar answer(same problem)
i have app.coffee :
pp.configure ->
publicDir = "#{__dirname}/public"
app.set "views", viewsDir
app.set "view engine", "jade"
app.use(stylus.middleware debug: true, src: viewsDir, dest: publicDir, compile: compileMethod)
app.use(express.static(publicDir))
compileMethod = (str, path) ->
stylus(str)
.set('filename', path)
.set('compress', true)
app.get "/pag",(req,res) ->
res.render "pag",
title: "test",
in /stylesheet/pag.jade:
...
link(rel='stylesheet', href='pag/css/bootstrap.min.css')
...
when im go to “myserver:9090/pag” the page not load the bootstrap.min.css.
i get the following error:
source :(my folder of proyects)/views/pag/css/bootstrap.min.styl
dest : (my folder of proyects)/public/pag/css/bootstrap.min.css
read : (my folder of proyects)/views/pag/css/bootstrap.min.styl
Error: ENOENT, open '(my folder)/views/pag/css/bootstrap.min.styl'
Where am i wrong? i am probably missing something.. any ideas?
First, if you haven’t set up ExpressJS to serve static files, you’ll want to do that:
app.use(express.static(__dirname + '/public'));Then, remove the “public” from your stylesheet call:
link(rel='stylesheet', href='/pag/css/bootstrap.min.css')You’re setting “public” as the app root directory that static files are being served from, so there’s no need to specify “public” in your call – “public” is now the root.
Update:
What is your
viewsDirset to? Since you’ve set the Stylus middleware’s source to that directory, that’s where it is looking for thestylto render.You’re setting “public” as the destination directory – if you include “public” in the call, it’ll just make another public directory under public, which isn’t what you want.
Try reorganizing the stylesheets in the project to something like this:
Then change your middleware to this:
app.use(stylus.middleware debug:true, src:'/stylesheets', dest: publicDir, compile: compileMethod)