为什么节点中间件不工作? [英] Why node-sass-middleware is not working?

查看:293
本文介绍了为什么节点中间件不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的快速应用程序中安装了 node-sass-middleware 模块,但是我并没有这样做,只是因为中间件读取的是不正确的源,当我调试控制台日志是:

  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
阅读:/ home / karim / snippets / my-financial / public / stylesheets / stylesheets / main.css

目录是错误的,为什么中间件在 / dest之间添加字符串 stylesheets / .. public / stylesheets / sass / )和 .sass文件 / .css文件 main.sass main.css ) ?



我的 app.js 中有这个配置:

  var sassMiddleware =要求(节点萨斯中间件); 
...
...
var app = express();

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

显然这并不是编译任何东西,因为目录是错误的。
在$ code> .. public / stylesheets / sass / 文件夹内我只有一个文件, main.sass 我想编译并将结果移动到 sass / 文件夹之外,我的意思是在 .. public / stylesheets /

解决方案

这是因为 - 我很确定 - 在你的html文件上有这样的东西:

 < head> 

<! - 所有的头部东西和 - >
< link rel =stylesheethref =/ stylesheets / main.css/>

< / head>

- 让我们把这个href称为你的爱好者一段时间。



当您的服务器收到任何 get 请求时,中间件将查找编译的 main.sass / home / karim / Snippets / my-financial / public / stylesheets dest yourAwesomeHref ,导致此路由:

  / Which那个文件显然根本不存在! 
所以你必须添加前缀:/ stylesheets在你的中间件避免这个问题。



最终的代码是:

  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:'compressed',
前缀:'/ 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: 'compressed'
}));

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

解决方案

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 compiled 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: 'compressed',
  prefix: '/stylesheets'
}));

这篇关于为什么节点中间件不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆