【问题标题】:Setting up nib and bootstrap-stylus设置 nib 和 bootstrap-stylus
【发布时间】:2013-11-06 21:37:46
【问题描述】:

我一直在使用 jetbrains webstorm IDE 玩节点。昨晚我试图设置 nib 和 bootstrap-stylus。但是我总是收到一个错误,即在导入标签中找不到 nib 或 bootstrap。

@import 'nib'

@import 'bootstrap'

但是如果我使用

@import '../../node_modules/bootstrap-stylus/lib/bootstrap'

一切都按预期进行。我不认为这是正确的方法?一定有某种方法可以告诉手写笔在哪里寻找导入?

我的 app.js 看起来像这样

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var nib = require('nib');
var bootstrap = require('bootstrap-stylus');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);

app.use(express.static(path.join(__dirname, 'public')));

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

app.use(stylus.middleware({
    src: path.join(__dirname, 'public')
    , compile: compile
}));

// development only
if ('development' == app.get('env')) {
    app.use(express.errorHandler());
}

app.get('/', routes.index); app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function () { console.log('Express 服务器监听端口' + app.get('port')); });

谢谢!

【问题讨论】:

    标签: node.js stylus


    【解决方案1】:

    应该像重写compile() 函数一样简单,如下所示:

    function compile(str, path) {
        return stylus(str)
            .set('filename', path)
            .set('compress', true)
            .use(nib())
            .use(bootstrap()); // each plugin has to be loaded
    }
    

    更多关于插件使用和手写笔的信息可以在这里找到:https://gist.github.com/jenius/8263065 并在官方文档中:http://learnboost.github.io/stylus/docs/js.html#usefn

    【讨论】:

      猜你喜欢
      • 2015-04-08
      • 2012-06-15
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      相关资源
      最近更新 更多