【问题标题】:Express.js - Less Middleware - Wrong paths generated when using separate foldersExpress.js - 更少的中间件 - 使用单独的文件夹时生成错误的路径
【发布时间】:2015-09-12 16:57:55
【问题描述】:

我使用的是默认的 lessMiddleware 设置,其中 已编译 .css 文件与其 .less 文件存储在同一文件夹中。

然后我切换到为我的cssless 文件使用单独的文件夹,并且从那时起我的.less 文件不再被编译成.css(基本上现在路径都是错误的 - 检查底部的调试日志)。我做错了什么?

文件夹结构:

  • .....
  • 公开
    • 款式
      • CSS
  • .....
  • app.js

app.js:

app.use(lessMiddleware(__dirname + '/public/styles/less', {
    force: true,
    dest: __dirname + '/public/styles/css',
    debug: true
}));

app.use(express.static(__dirname + "/public"));

app.get('/', function(req, res, next) 
{
    res.render('index.ejs');
});

index.ejs:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/styles/css/animations.css"/>
        <link rel="stylesheet" type="text/css" href="/styles/css/global.css"/>
        ........
        ............

减少调试日志:

  pathname : /styles/css/animations.css
  source : /Users/mothership/testapp/public/styles/less/styles/css/animations.less
  destination : /Users/mothership/testapp/public/styles/css/styles/css/animations.css
  pathname : /styles/css/global.css
  source : /Users/mothership/testapp/public/styles/less/styles/css/global.less
  destination : /Users/mothership/testapp/public/styles/css/styles/css/global.css

【问题讨论】:

    标签: node.js express less


    【解决方案1】:

    原来的解决方案如下(也许有一个更干净的,但我找不到它):

    app.use(lessMiddleware(__dirname + '/public/styles/less', {
        force: true,
        dest: __dirname + '/public',
        debug: true,
        preprocess: {
            path: function(pathname, req) {
              return pathname.replace(/styles\/css\//, '');
            }
          }
    }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 2013-03-08
      • 1970-01-01
      • 2020-03-27
      相关资源
      最近更新 更多