我最近开始学习Node.js,我正在尝试使用较少的中间件设置快速安装,并希望使用Bootstrap 3减少文件。我已经浏览了一下,但只能找到Bootstrap 2的教程。
到目前为止,这是我的代码:
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
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(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('less-middleware')({
dest: __dirname + '/public/stylesheets',
src: __dirname + '/public/stylesheets/less',
prefix: '/stylesheets',
compress: true,
debug: true,
force: true
}));
app.use(express.static(path.join(__dirname, 'public')));
// 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'));
});
当我运行服务器时,我得到以下内容:
GET / 200 190ms - 180b
source : /home/user/www/website.com/public/stylesheets/less/bootstrap.less
dest : /home/user/www/website.com/public/stylesheets/bootstrap.css
read : /home/user/www/website.com/public/stylesheets/less/bootstrap.less
render : /home/user/www/website.com/public/stylesheets/less/bootstrap.less
GET /stylesheets/bootstrap.css 200 565ms - 97.43kb
但我改变的风格似乎并没有生效。有人能告诉我哪里出错了吗?
由于
答案 0 :(得分:2)
使用它来自较少中间件的github页面,它现在正常工作。
var less = require('less-middleware');
app.configure(function(){
// ...
var bootstrapPath = path.join(__dirname, 'node_modules', 'bootstrap');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use('/img', express['static'](path.join(bootstrapPath, 'img')));
app.use(app.router);
app.use(less({
src : path.join(__dirname, 'public/stylesheets', 'less'),
paths : [path.join(bootstrapPath, 'less')],
dest : path.join(__dirname, 'public', 'stylesheets'),
prefix : '/stylesheets',
debug: true
}));
app.use(express['static'](path.join(__dirname, 'public')));
// ...
});