尝试使用gulp-less编译bootstrap时遇到此错误:
./node_modules/.bin/gulp
[11:36:31] Using gulpfile ~/Desktop/elfet.github.io/gulpfile.js
[11:36:31] Starting 'default'...
[11:36:31] Finished 'default' after 21 ms
/Users/anton/Desktop/elfet.github.io/node_modules/gulp-less/node_modules/accord/node_modules/when/lib/decorators/unhandledRejection.js:80
throw e;
^
SyntaxError: Unexpected token u in file undefined line no. undefined
at Object.parse (native)
at /Users/anton/Desktop/elfet.github.io/node_modules/gulp-less/node_modules/accord/lib/adapters/less.js:48:32
怎么办? 在这里我的gulpfile:
gulp.task('default', function () {
gulp.src('src/less/*.less')
.pipe(sourcemaps.init())
.pipe(less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
答案 0 :(得分:1)
您在https://github.com/less/less.js/issues/2452发布了同样的问题。您展示了修改后的bootstrap.less
文件,我认为您不需要进行这些修改。
您应该创建一个文件src/less/project.less
,其中包含以下代码:
@import "../../bower_components/bootstrap/less/bootstrap.less";
运行bower install bootstrap
后,上述内容可用于:
var gulp = require('gulp'),
less = require('gulp-less');
gulp.task('default', function () {
gulp.src('src/less/*.less')
.pipe(less())
.pipe(gulp.dest('css'));
});
现在运行grunt
命令将创建包含已编译的Bootstrap代码的css/project.css
。