I've been playing around with node using jetbrains webstorm IDE. Last night I was trying to setup nib and bootstrap-stylus. However I always get an error that nib or bootstrap cant be found in the import tags.

@import 'nib'

or

@import 'bootstrap'

however if i use

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

everything works as expected. I don't think this is the right way? there must be some way to tell stylus where to look for imports?

my app.js looks like this

/**
 * 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 server listening on port ' + app.get('port')); });

Thanks!

有帮助吗?

解决方案

It should be as simple as rewriting your compile() function as follows:

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

More information about plugin usage and stylus can be found here: https://gist.github.com/jenius/8263065 And in the official documentation: http://learnboost.github.io/stylus/docs/js.html#usefn

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top