跳到主要內容

[教學] stylus & nib express on node.js

stylus & nib express on node.js

CSS 架構上也許有點難寫,難看,stylus 就是用來簡化 CSS 的架構,stylus 可以讓 css 自定變數,自定 mixin ,nib 就可以視為將 stylus 強化的 framework.




stylus

stylus 是一套以 sass 為標準的 node.js module,讓開發者可以在 node.js 上面直接編寫 sass,即時編譯成 css 檔案。

nib

nib 是集合 stylus 常用的 mixin 為大全的 sass framework,例如在樣式中經常用的 Border radius, Clearfix, Gradients 等,已經收錄在裡面,當然自己也可以建立自己的 mixin,讓開發 css 變得更為簡單。

express 整合

express,用於建構 node.js web service 的模組,網路上已有許多說明,express 路徑相關處理可以參考文章,基本需要使用的 static file 路徑設定。

app.configure(function(){
  app.use(express['static'](__dirname + '/public'));
});

增加 stylus 以及 nib


var stylus = require("stylus"), 
    nib = require("nib");

stylus 我們只需要在開發環境裡面使用即可,因此設定如下,

app.configure('development', function(){
  var stylusMiddleware = stylus.middleware({
  src: __dirname + '/stylus/', // .styl files are located in `/stylus`
  dest: __dirname + '/public/', // .styl resources are compiled `/css/*.css`
  debug: true,
  compile: function(str, path) { // optional, but recommended
    return stylus(str)
      .set('filename', path)
      .set('warn', true)
      .set('compress', true)
      .use(nib());
    }
  });
  app.use(stylusMiddleware);  
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

後記

stylus + nib 在 node.js 環境底下是個開發 css 優秀的選擇,當然你也可以安裝 compass 來處理同樣的問題,不過既然都使用 Node.js ,而且已經有既有的模組可以使用,個人會參考讓環境單純化。

Node.js Taiwan 社群裡面,攥寫基本的開發手冊,Node.js 台灣社群協作電子書,需要更多人的投入,如果有中文相關資料願意投入,歡迎與我聯繫。

Node.JS Knockout 一年一度的黑客頌活動,即將於 11 月開始,錯過了今年,就要等到明年,快點加入吧!

留言

這個網誌中的熱門文章

[CSS] z-index 在不同瀏覽器繼承問題

今天會討論到這個課題,是因為要實做一個Popup dialog,所以我們希望的結果如下圖。 可是在IE7 卻發生了這樣的情況。 Popup不論怎麼設定z-index都無法浮在最上層,我們看一下html架構發生什麼事情。

[教學] 快快樂樂刪除CodeIgniter index.php

預設的CI網址預設都設定為index.php同一層級,因此所有的程式都必須指定index.php導向才能開始,例如 http://localhost/ci/index.php/welcome/test http://localhost/ci/welcome/test 本文將說明如何將惱人的index.php消除,還你一個漂亮的URL。 設定開始: 接下來說明如何使用rewrite方式將惱人的index.php去除。 rewrite不清楚的人,煩請先自行google 首先要先確定Apache的 mod_rewrite 有 開啟 ,如果沒有開啟請設定好之後重新啟動apache。 接著,在根目錄底下建立一個新檔案,檔名為 .htaccess ,裡面程式碼如下: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> 接著到 application/config/config.php ,開啟檔案修改 $config['index_page'] = ""; 注意: /index.php/$1 要根據你目錄,例如 http://localhost/index.php ,網站根目錄為 /ci/index.php 則要寫成 /ci/index.php/$1 接著至CI目錄下,尋找 config\config.php , 修改一下裡面的檔案,修改如下: $config['index_page'] = ""; 存檔後,如此一來大功告成。 參考資料 官方網站說明

AI-Native Agent 時代的 2026 年身為管理者應該知道的事情

AI-Native Agent 時代的 AI-Native Engineering 從 Andrew Ng 的 AI Engineering Skills Map,到 2026 年 9 月真正正在成形的 Agent-first Software Development 2026 年 9 月 4 日,Andrew Ng 發表了 AI Engineering Skills Map 系列中關於 Using Coding Agents 的文章,同時期 Claude, Cursor, OpenAI 也發表了許多架構,經驗談,以及商業上的應用,此時將眾家以及自己在正美科技所進行的事情進行彙整,讓大家可以少走些彎路,少踩些坑。 以下這些文章,有點長度,但他對於技術人,對於商業人,對於想要 AI 導入到自己公司的人都會有所幫助,不論你想要自己 vibe coding 或者是你是想要更近一步的 AI 自媒體老師,都應該完整閱讀這篇文章 同時我也希望你可以給我更多回饋,或者加入社團討論 「AI for Developer LINE 社群連結」 本文開始 如果把整篇文章和 2026 年正在發生的事情放在一起看,以及結合自己在開發 cymkube & cympack 的經驗來說,將整個 ai 智能製造 (ai manufacturing) 的過程來說,回歸到軟體工程,可以歸納成一段話。 軟體工程正在從「Human 寫 Code,AI 幫忙」轉向「Human 定義 Intent、Architecture、Constraints 與 Acceptance Criteria,Agent 負責 Execution,而系統負責 Verification」。 回歸過去就是: 2024 Human writes code AI assists ↓ 2025 Human prompts Agent edits code ↓ 2026 Human specifies intent Agents execute in parallel Verifiers inspect output Humans make judgment ↓ Next Human manages an engineering system ...