我正在尝试使用gulp来编译sass到css使用gulp-sass库gulp-sass。但是sass编译任务不会生成任何内容,也不会抛出任何错误日志。我已经通过npm install -g sass
这是我设置的项目。
Gulp文件内容:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src('./src/index.scss').pipe(sass()).pipe(gulp.dest('./css'));
});
Sass内容:
xuanyue$ cat src/index.scss
@import './variable';
body{
background: $color;
}
xuanyue$ cat src/variable.scss
$color: #fff
用法:
xuanyue$ tree -L 2 -I node_modules
.
├── css
├── gulpfile.js
├── package-lock.json
├── package.json
└── src
├── index.scss
└── variable.scss
2 directories, 5 files
xuanyue$ gulp sass
[17:31:04] Using gulpfile ~/Downloads/test-gulp/gulpfile.js
[17:31:04] Starting 'sass'...
[17:31:04] Finished 'sass' after 8.72 ms
LM-CHD-21016754:test-gulp jinxwu$ tree -L 2 -I node_modules
.
├── css
├── gulpfile.js
├── package-lock.json
├── package.json
└── src
├── index.scss
└── variable.scss
2 directories, 5 files
的package.json
xuanyue$ cat package.json
{
"name": "test-gulp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"gulp": "^3.9.1",
"natives": "git+https://github.com/addaleax/natives.git"
},
"devDependencies": {
"gulp-sass": "^4.0.1"
}
}
答案 0 :(得分:0)
只需在variables.scss
文件
$color: #fff;
可能是编译器抛出错误而且文件没有被编译。