0

Im trying to import multiple scss files in my app.scss file but gulp is throwing an error:

//app.scss
@import "base";

body {
   background: #fff;
}

gulpfile.js

gulp.task('build-css', function () {
    return gulp.src(assetsDev + 'scss/*.scss')
        .pipe(sourcemaps.init())
        .pipe(postcss([precss, autoprefixer, cssnano]))
        .pipe(sourcemaps.write())
        .pipe(ext_replace('.css'))
        .pipe(gulp.dest(assetsProd + 'css/'));
});

Directory structure:

├── assets
│   └── scss
│       ├── _base.scss
│       └── app.scss
├── src
│   └── css
│       └── style.css
└── gulpfile.js

And gulp is throwing this error:

events.js:141
  throw er; // Unhandled 'error' event
  ^
Error: ENOENT: no such file or directory, open '...\assets\scss\_base.css'
at Error (native)
4

1 回答 1

1

precss uses the postcss-partial-import plugin for @import statements. By default it assumes that the extension of imported partials is css.

You need to either provide the full file name (with extension) in all of your @import statements:

@import "_base.scss";

body {
  background: #fff;
}

Or you need to pass the extension option to precss():

gulp.task('build-css', function () {
  return gulp.src(assetsDev + 'scss/*.scss')
    .pipe(sourcemaps.init())
    .pipe(postcss([precss({extension:'scss'}), autoprefixer, cssnano]))
    .pipe(sourcemaps.write())
    .pipe(ext_replace('.css'))
    .pipe(gulp.dest(assetsProd + 'css/'));
});
于 2016-05-06T14:29:20.637 回答