我使用默认的lessMiddleware设置,其中已编译的 .css
文件存储在与源 .less
文件相同的文件夹中。< / p>
然后我切换到为css
和less
文件使用单独的文件夹,然后我的.less
文件不再编译为.css
了(基本上是路径现在都错了 - 请查看底部的调试日志。我做错了什么?
文件夹结构:
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
答案 0 :(得分:0)
原来解决方案如下(可能有一个更干净但我无法找到它):
app.use(lessMiddleware(__dirname + '/public/styles/less', {
force: true,
dest: __dirname + '/public',
debug: true,
preprocess: {
path: function(pathname, req) {
return pathname.replace(/styles\/css\//, '');
}
}
}));