我一直在使用 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 server监听端口' + app.get('port')); });
谢谢!