99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Stylus 連接中間件

2023-09-11 13:54 更新

連接中間件(Connect Middleware)

連接中間件

有了連接中間件,無(wú)論Stylus片段什么時(shí)候改變,這些片段都能夠自動(dòng)編譯。

stylus.middleware(options)
選項(xiàng)

返回給定options下的連接中間件。

`serve`     Serve the stylus files from `dest` [true]
`force`     Always re-compile
`src`       Source directory used to find .styl files
`dest`      Destination directory used to output .css files
            when undefined defaults to `src`.
`compile`   Custom compile function, accepting the arguments
           `(str, path)`.
`compress`  Whether the output .css files should be 
            compressed
`firebug`   Emits debug infos in the generated css that can
            be used by the FireStylus Firebug plugin
`linenos`   Emits comments in the generated css indicating 
            the corresponding stylus line

上面中文翻譯如下:

`serve`     從 `dest` 提供stylus文件 [true]
`force`     總是重新編譯
`src`       資源目錄用來(lái)查找 .styl 文件
`dest`      `src`默認(rèn)為undefined時(shí),用來(lái)輸出 .css 文件的目標(biāo)目錄
`compile`   自定義編譯函數(shù),接受參數(shù)`(str, path)`.
`compress`  是否輸出的 .css 文件要被壓縮
`firebug`   生成的CSS中發(fā)出調(diào)試信息,可被Firebug插件FireStylus使
            用
`linenos`   生成的CSS中發(fā)出注解,表明響應(yīng)的stylus行
例子

從./public提供.styl文件。

var app = connect();

app.middleware(__dirname + '/public');

改變src以及dest項(xiàng)來(lái)修改.styl文件哪里被加載,哪里被保存。

var app = connect();

app.middleware({
  src: __dirname + '/stylesheets',
  dest: __dirname + '/public'
});

這里我們建立自定義的編譯函數(shù),這樣,我們就能設(shè)置compress項(xiàng),或是定義附加的函數(shù)。

默認(rèn)情況下,編譯函數(shù)是簡(jiǎn)單地設(shè)置filename以及渲染CSS. 在下面這個(gè)例子中,我們壓縮輸出內(nèi)容,使用"nib"庫(kù)插件,以及自動(dòng)導(dǎo)入。

function compile(str, path) {
  return stylus(str)
    .set('filename', path)
    .set('compress', true)
    .use(nib())
    .import('nib');
}

作為選項(xiàng)傳遞應(yīng)該像這樣:

var app = connect();

app.middleware({
    src: __dirname
  , dest: __dirname + '/public'
  , compile: compile
})


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)