Import CSS from node_modules using Gulp-SASS

前端 未结 2 1672
Happy的楠姐
Happy的楠姐 2021-02-08 04:08

I want to import a CSS-file from my node_modules using SASS.

@import \'normalize.css/normalize\';
<         


        
2条回答
  •  旧巷少年郎
    2021-02-08 04:27

    What works for me, in 2020, is this:

    function styles() {
        return (
          gulp.src(paths.styles.src)
            .pipe(sourcemaps.init())
            .pipe(sass({
                        includePaths: ['./node_modules/purecss-sass/vendor/assets/stylesheets/',
                                      './node_modules/modularscale-sass/stylesheets/',
                                      './node_modules/typi/scss/'
                                      ]
                      }))
            .on("error", sass.logError)
            .pipe(postcss([autoprefixer(), cssnano()]))
            .pipe(sourcemaps.write())
            .pipe(gulp.dest(paths.styles.dest))
            .pipe(browserSync.stream())
        );
    }
    

    Now in the scss files, I can

    @import 'modularscale';
    @import 'typi';
    @import 'purecss';
    

    The other options seem to be:

    1. put the full paths to the main _somelibrary.scss file directly in the scss files (minus the extension), so something like:
    @import '../../node_modules/purecss-sass/vendor/assets/stylesheets/_purecss';
    
    1. Put includePaths: ['./node_modules'] and add the relative paths in the scss files:
    @import 'purecss-sass/vendor/assets/stylesheets/_purecss';
    

提交回复
热议问题