我不知道为什么,但这段代码在一段时间后停止工作。它正在缩小代码但不添加任何供应商前缀。我还想像 normalize 一样向 css 添加另一个文件,但它也不起作用。这是代码:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
dist: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> filename.min.js <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %> */\n',
},
files: {
'js/scripts.min.js' : [
]
}
},
dev: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> filename.js <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %> */\n',
beautify: true,
compress: false,
mangle: false
},
files: {
'js/scripts.js' : [
]
}
}
},
sass: {
dist: {
options: {
compass: true,
style: 'expanded'
},
files: [{
expand: true,
cwd: 'sass',
src: [
'style.scss'
],
dest: 'css',
ext: '.css'
}]
}
},
watch: {
styles: {
files: ['**/*.scss'],
tasks: ['style']
}
},
postcss: {
options: {
map: {
inline: false, // save all sourcemaps as separate files...
annotation: 'css/maps/' // ...to the specified directory
},
processors: [
require('pixrem')(), // add fallbacks for rem units
require('autoprefixer')({browsers: ['last 3 versions']}), // add vendor prefixes
require('cssnano')() // minify the result
]
},
dist: {
src: 'css/style.css',
dest: 'css/styles.min.css'
}
}});
编辑,我在片段中包含了整个 grunt 文件。
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
dist: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> filename.min.js <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %> */\n',
},
files: {
'js/scripts.min.js' : [
]
}
},
dev: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> filename.js <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %> */\n',
beautify: true,
compress: false,
mangle: false
},
files: {
'js/scripts.js' : [
]
}
}
},
sass: {
dist: {
options: {
compass: true,
style: 'expanded'
},
files: [{
expand: true,
cwd: 'sass',
src: [
'style.scss'
],
dest: 'css',
ext: '.css'
}]
}
},
watch: {
styles: {
files: ['**/*.scss'],
tasks: ['style']
}
},
postcss: {
options: {
map: {
inline: false, // save all sourcemaps as separate files...
annotation: 'css/maps/' // ...to the specified directory
},
processors: [
require('pixrem')(), // add fallbacks for rem units
require('autoprefixer')({browsers: ['last 3 versions']}), // add vendor prefixes
require('cssnano')() // minify the result
]
},
dist: {
src: 'css/style.css',
dest: 'css/styles.min.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-postcss');
// Default task(s).
grunt.registerTask('style', [
'sass',
'postcss'
]);
// Default task(s).
grunt.registerTask('default', [
'uglify:dist',
'sass',
'postcss',
'watch'
]);
};