我有一个core.styl,我在其中放置了我的网格样式、一些手写笔功能和一些变量。这个文件应该在我的所有路由中导入。
除此之外,我还有一个 page.styl,它取决于我当前的路线(例如/contact 的contact.styl )
注意:我的项目基于 angular.js,所以 html-head 不会重载。但我可以在 html-head 中添加一些有角度的东西,比如.
我试过以下
//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
|