首页 > 解决方案 > Grunt-Sass 如何防止 CSS 解压

问题描述

我在我的项目中使用GRUNT-SASS,我使用的是 normalize.css 的缩小版本,并将它放在名为 _reset.scss 的部分上。我的问题是,GRUNT-CSS 在保存时将其转换为未压缩/美化版本(在 .css 文件中)。当我将其添加为部分 SCSS 文件中的压缩文件时,我想将其保存为压缩的 .css。有没有办法做到这一点?

这是我的 grunfile.js:

// The "wrapper" function
module.exports = function(grunt) {

const sass = require('node-sass');

// Project and task c onfiguration
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    /**
     * Grunt Sass
     * Compile Sass to CSS using node-sass
     * https://www.npmjs.com/package/grunt-sass
     */
    sass: {
        options: {
                implementation: sass,
                sourceMap: true
        },
        dist: {
                files: {
                        'style.css' : 'assets/scss/main.scss'
                }
        }
    },

    /**
     * Grunt Contrib Watch
     * Monitor files and execute tasks
     * https://www.npmjs.com/package/grunt-contrib-watch
     */
    watch: {
        sass: {
            files: [
                'assets/scss/*.scss'
            ],
            tasks: [
                'sass'
            ]               
        }
    }


});

// Load all grunt tasks matching the ['grunt-*', '@*/grunt-*'] patterns
require('load-grunt-tasks')(grunt); 

// Custom tasks
grunt.registerTask('default', ['watch']);
};

标签: csssassgruntjsnode-sass

解决方案


推荐阅读