我有一个core.styl,在这里我放置了网格样式、一些手写函数和一些变量。这个文件应该在我的路由的所有中导入。
除此之外,我还有一个page.styl,它取决于我目前的路线(例如,contact.styl for /contact)
注意:我的项目是基于angular.js的,所以html-head不会重新加载。但是我可以在html中添加一些有角的东西,比如<link href="contact.css">。
我试着跟着
//index.html
<link rel="stylesheet" href="/css/core.css" /> <-- this is static, always there
<link rel="stylesheet" href="/css/pages/contact.css" /> <-- added by angular问题:在contact.styl中,我对我的手写变量和函数有无访问(在core.styl中声明)
一种解决方案:每个页面样式表中的@import '../core.styl'。但对我来说是不可能的。
还有别的办法我可以试试吗?
也许是这样的(server.js)?
function compile(str, path) {
return stylus(str)
.import(config.path_client + "/css/core")
.set('filename', path)
.set('warn', true)
.set('compress', true);
}
app.use(stylus.middleware({
src: config.path_client + '/css/pages',
compile: compile
}));(试了很长时间,但对我仍然不起作用)
编辑:我的文件结构:
|client
||css
|||pages
||||-contact.styl
||||-contact.css
|||base
||||-core.styl
||||-core.css
|server
||-server.js
|发布于 2015-03-06 08:38:02
您可以使用JS并使用define方法定义这些vars。请参阅http://learnboost.github.io/stylus/docs/js.html#definename-node
https://stackoverflow.com/questions/28888410
复制相似问题