我正在使用 Grunt 编译 SASS 并缩小 CSS (grunt-contrib-sass + grunt-contrib-cssmin)。我对每个项目都进行了相同的设置,而且它总是很完美,但最近我注意到 grunt-contrib-sass 在这个项目上输出了巨大的 CSS 文件(48Mb)。我已经对其进行了研究,无法找出它可能是什么,而且由于这个设置曾经有效,我不知道要寻找什么。在我的实际 SASS 中是否有任何东西可能会使编译的文件如此之大?
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
sass: {
dist: {
files: {
'dist/css/main.css': 'assets/sass/main.scss'
}
}
},
cssmin: {
build: {
src: 'dist/css/main.css',
dest: 'dist/css/main.min.css'
}
},
concat: {
options: {
separator: '\n/*next file*/\n\n'
},
dist: {
src: ['assets/js/main.js'],
dest: 'dist/js/built.js'
}
},
uglify: {
build: {
files: {
'dist/js/built.min.js': ['dist/js/built.js']
}
}
},
watch: {
sass: {
files: '**/**/*.scss', // ** any directory; * any file
tasks: ['css'],
options: {
livereload: 35729 // 35729 is the default port === true
}
},
concat: {
files: ['assets/js/main.js'],
tasks: ['concat']
},
uglify: {
files: 'dist/js/built.js',
tasks: ['uglify'],
options: {
livereload: true
}
},
all: {
files: ['**/*.php'],
options: {
livereload: true
}
}
}
});
// grunt.registerTask(taskName, [optional description, ] taskFunction);
grunt.registerTask('default', ['sass', 'cssmin', 'concat', 'uglify']);
grunt.registerTask('css', ['sass', 'cssmin']);
grunt.registerTask('sass', ['sass']);
grunt.registerTask('cssmin', ['cssmin']);
grunt.registerTask('js', ['concat', 'uglify']);
// grunt.loadNpmTasks('yourplugin');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
};
包.json
{
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-coffee": "~0.12.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-sass": "^0.7.4",
"grunt-contrib-uglify": "^0.5.1",
"grunt-contrib-watch": "^0.6.1"
}
}