我知道这里发布了类似的问题,但没有一个能帮助我弄清楚出了什么问题。当我在我的cmd中运行grunt(我在Windows 10上)时,我收到此消息:
加载“Gruntfile.js”任务......错误
SyntaxError:意外的标识符 警告:找不到任务“默认”。使用--force继续
我觉得我用细齿梳子完成了我的代码,但我看不出问题。这是我的Gruntfile.js:
module.exports = function (grunt) {
//Config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
dev: {
options: {
beautify: true,
mangle: false,
compress: false,
preserveComments: 'all'
},
src: 'src/js/*.js',
dest: 'js/script.min.js'
},
build: {
src: 'src/js/*.js',
dest: 'js/script.min.js'
}
},
sass: {
dev: {
options: {
outputstyle: 'expanded'
},
files:{
'css/style.css': 'src/scss/style.scss'
}
},
build: {
options: {
outputstyle: 'compressed'
},
files: {
'css/style.css': 'src/scss/style.scss'
}
}
},
postcss: {
options: {
map: false,
processors: [
require('pixrem')(),
require('autoprefixer')({browsers: 'last 2 versions'}),
require('cssnano')()
]
}
build: {
src: 'css/*.css'
}
},
watch: {
js: {
files: ['src/js/*.js'],
tasks: ['uglify:dev']
},
sass:{
files: ['src/scss/*.scss'],
tasks: ['sass:dev']
}
}
});
//Load
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-watch');
//Register
grunt.registerTask('default', ["uglify:dev", "sass:dev"]);
grunt.registerTask('build', ['uglify:build', 'sass:build', 'postcss:build']);
};