【发布时间】:2015-03-05 21:48:36
【问题描述】:
我有一个 core.styl,我在其中放置了我的网格样式、一些手写笔功能和一些变量。此文件应导入我的所有路线中。
除此之外,我还有一个 page.styl,它取决于我当前的路线(例如 contact.styl 用于 /contact)
注意:我的项目基于 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
|
【问题讨论】:
标签: angularjs global-variables middleware stylus file-structure