問題描述
我正在使用 Gulp 將我的 sass 編譯成 css.一個簡單的任務編譯 _/sass
目錄中的 style.scss
文件,并將輸出保存到項目的根目錄中.style.scss
僅用于導入 _/sass
目錄下的其他文件.
I'm using Gulp to compile my sass into css. A simple task compiles the style.scss
file in the _/sass
directory and saves the output into the root of the project. style.scss
is used merely to import other files in the _/sass
directory.
當我從命令行 ($ gulp
) 運行默認任務時,我收到一個 sass 無法編譯的錯誤.它全部包含在下面.我已從包含的文件中刪除所有內容并再次運行該任務.我仍然收到相同的錯誤(我在網上閱讀的內容表明這可能會測試編碼問題.我不完全了解編碼以及這可能會如何破壞我的場景).
When I run the default task from the command line ($ gulp
) I get an error that the sass can't compile. It is included below in full. I have removed all content from the included files and run the task again. I still receive the same error (something I read online suggested this might test for an encoding issue. I don't fully understand encoding and how that might break things in my scenario).
我還從命令行 $ sass _/sass/style.scss style.css
運行,它與包含文件中的內容完美配合.這表明 gulp sass 插件本身存在問題.
I've also run from the command line $ sass _/sass/style.scss style.css
which works perfectly with content in the included files. This suggests to me a problem with the gulp sass plugin itself.
來自 gulpfile.js 的相關片段:
The relevant snippets from gulpfile.js:
var gulp = require('gulp');
var sass = require('gulp-sass');
// Compile sass files
gulp.task('sass', function () {
gulp.src('./_/sass/style.scss')
.pipe(sass())
.pipe(gulp.dest('./'));
});
// The default task (called when you run `gulp`)
gulp.task('default', function() {
gulp.run('sass');
// Watch files and run tasks if they change
gulp.watch(['./_/sass/style.scss'], function() {
gulp.run('sass');
})
});
style.scss的全部內容:
The full contents of style.scss:
/* RESET */
@import '_/sass/reset';
/* TYPOGRAPHY */
@import '_/sass/typography';
/* MOBILE */
@import '_/sass/mobile';
/* MAIN */
@import '_/sass/main';
目錄結構:
├── _
│?? ├── inc
│?? │?? ├── stuff
│?? ├── js
│?? │?? ├── otherstuff.js
│?? └── sass
│?? ├── main.scss
│?? ├── mobile.scss
│?? ├── print.scss
│?? ├── reset.scss
│?? ├── style.scss
│?? └── typography.scss
├── gulpfile.js
└── style.css
終端吐出:
[gulp] Using file /Users/jeshuamaxey/project/dir/path/gulpfile.js
[gulp] Working directory changed to /Users/jeshuamaxey/project/dir/path/html5reset
[gulp] Running 'default'...
[gulp] Running 'sass'...
[gulp] Finished 'sass' in 3.18 ms
[gulp] Finished 'default' in 8.09 ms
stream.js:94
throw er; // Unhandled stream error in pipe.
^
source string:11: error: file to import not found or unreadable: 'reset'
推薦答案
保持導入不變,只需在 gulp sass 模塊中傳遞 includePaths
選項作為參數:
Keep your imports as is, just pass the includePaths
option in your gulp sass module as an argument:
gulp.src('./_/sass/style.scss')
.pipe(sass({ includePaths : ['_/sass/'] }))
.pipe(gulp.dest('./'));
...應該為你做.
根據 https://github.com/dlmanning/gulp-sass/issues/1
這篇關于Gulp-sass 無法編譯 scss 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!