javascript - Why node-sass-middleware is not working? - Stack Overflow

I have installed the node-sass-middleware module on my express application, but i'm not getting th

I have installed the node-sass-middleware module on my express application, but i'm not getting that working, just because the middleware is reading an incorrect source, when i debug the console log is:

GET / 200 558.983 ms - 4651
  source: /home/karim/Snippets/my-financial/public/stylesheets/sass/stylesheets/main.sass
  dest: /home/karim/Snippets/my-financial/public/stylesheets/stylesheets/main.css
  read: /home/karim/Snippets/my-financial/public/stylesheets/stylesheets/main.css

which both directories are wrong, why the middleware is adding the string stylesheets/ between the source/dest (..public/stylesheets/sass/) and the .sass file/.css file (main.sass and main.css)?

I have this configuration inside my app.js:

var sassMiddleware = require('node-sass-middleware');
...
...
var app = express();

app.use(sassMiddleware({
  src: path.join(__dirname, 'public/stylesheets/sass'),
  dest: path.join(__dirname, 'public/stylesheets'),
  debug: true,
  indentedSyntax: true,
  outputStyle: 'pressed'
}));

Obviously this is not piling anything, becuase the directories are wrong. Inside the ..public/stylesheets/sass/ folder i just have one file, main.sass which i want to pile and move the result outside the sass/ folder, i mean at ..public/stylesheets/.

I have installed the node-sass-middleware module on my express application, but i'm not getting that working, just because the middleware is reading an incorrect source, when i debug the console log is:

GET / 200 558.983 ms - 4651
  source: /home/karim/Snippets/my-financial/public/stylesheets/sass/stylesheets/main.sass
  dest: /home/karim/Snippets/my-financial/public/stylesheets/stylesheets/main.css
  read: /home/karim/Snippets/my-financial/public/stylesheets/stylesheets/main.css

which both directories are wrong, why the middleware is adding the string stylesheets/ between the source/dest (..public/stylesheets/sass/) and the .sass file/.css file (main.sass and main.css)?

I have this configuration inside my app.js:

var sassMiddleware = require('node-sass-middleware');
...
...
var app = express();

app.use(sassMiddleware({
  src: path.join(__dirname, 'public/stylesheets/sass'),
  dest: path.join(__dirname, 'public/stylesheets'),
  debug: true,
  indentedSyntax: true,
  outputStyle: 'pressed'
}));

Obviously this is not piling anything, becuase the directories are wrong. Inside the ..public/stylesheets/sass/ folder i just have one file, main.sass which i want to pile and move the result outside the sass/ folder, i mean at ..public/stylesheets/.

Share Improve this question asked Jun 4, 2015 at 21:16 user3697569user3697569
Add a ment  | 

1 Answer 1

Reset to default 12

That is because -- i am pretty sure -- on your html file there is something like that:

<head>

  <!--All your head stuff and-->
  <link rel="stylesheet" href="/stylesheets/main.css"/>

</head>

-- Lets call that href as yourAwesomeHref for a moment.

When your server receive any get request, the middleware will look for the piled main.sass on /home/karim/Snippets/my-financial/public/stylesheets (dest option for the middleware) following by yourAwesomeHref, resulting this route:

/home/karim/Snippets/my-financial/public/stylesheets/stylesheets/main.css

Which that file obviously does not exist at all! So you have to add prefix: "/stylesheets" on your middleware for avoid that problem.

The final code is:

var sassMiddleware = require('node-sass-middleware');
...
...
var app = express();

app.use(sassMiddleware({
  src: path.join(__dirname, 'public/stylesheets/sass'),
  dest: path.join(__dirname, 'public/stylesheets'),
  debug: true,
  indentedSyntax: true,
  outputStyle: 'pressed',
  prefix: '/stylesheets'
}));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743722143a4496002.html

相关推荐

  • javascript - Why node-sass-middleware is not working? - Stack Overflow

    I have installed the node-sass-middleware module on my express application, but i'm not getting th

    6天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信