我正在创建gruntfile并安装所有必需的依赖项。 在教程中一切正常但不适合我。 如果我尝试运行此gruntfile,我会看到以下错误消息:
错误:无法找到模块'pixrem' 警告:找不到任务“默认”。使用--force继续。 因警告而中止。
哪里出错?如果可以,请纠正答案中的错误。 Gruntfile在这里:
module.exports = function(grunt) {
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
watch : {
images : {
files : ['images/src/**/*.{png,jpg,gif}'],
tasks : ['newer:imagemin']
}, // watch images added to src
deleting : {
files : ['images/src/*.{png,jpg,gif}'],
tasks : ['delete_sync']
}, // end of delete sync
scripts : {
files : ['js/libs/*.js', 'js/custom/*.js'],
tasks : ['concat', 'uglify'],
options : {
spawn : false,
}
}, //end of watch scripts
css : {
files : ['sass/**/*.scss'],
tasks : ['sass', 'postcss', 'penthouse'],
options : {
spawn : false,
}
}, //end of sass watch
grunt : {
files : ['gruntfile.js']
}
}, //end of watch
/* ====================================================================================================================================================
* ====================================================================================================================================================
Tasks
====================================================================================================================================================
====================================================================================================================================================
*/
delete_sync : {
dist : {
cwd : 'images/dist',
src : ['**'],
syncWith : 'images/src'
}
}, // end of delete sync
imagemin : {
dynamic : {
files : [{
expand : true, // Enable dynamic expansion
cwd : 'images/src/', // source images (not compressed)
src : ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest : 'images/dist/' // Destination of compressed files
}]
}
}, //end imagemin
concat : {
dist : {
src : ['js/libs/*.js', 'js/custom/*.js'],
dest : 'js/build/production.js'
}
}, //end concat
uglify : {
dist : {
src : 'js/build/production.js',
dest : 'js/build/production.min.js'
}
}, //end uglify
sass : {
dist : {
options : {
style : 'nested', //no need for config.rb
compass : 'true'
},
files : {
'css/main.css' : 'sass/main.scss'
}
}
}, //end of sass
postcss : {
options : {
map : true,
processors : [require('pixrem')(), // add fallbacks for rem units
require('autoprefixer-core')({
browsers : 'last 2 version, IE 9'
}), // add vendor prefixes. for more: https://github.com/ai/browserslist
require('cssnano')() // minify the result
]
},
dist : {
src : 'css/main.css'
}
},
penthouse : {
extract : {
outfile : 'css/critical.css.php',
css : 'css/main.css',
url : 'http://localhost/grunt-boilerplate',
width : 1200,
height : 500
},
}, //end of penthouse
browserSync : {
dev : {
bsFiles : {
src : ['css/*.css', 'images/*.*', 'js/build/production.min.js', '*.php', 'includes/*.php', '!.sass-cache']
},
options : {
proxy : "localhost/grunt-boilerplate",
watchTask : true
}
}
},
ftpush : {
build : {
auth : {
host : 'ftp.yourwebsite.com',
port : 21,
authKey : 'key1' //ftp login is in the .ftppass file
},
src : './', //root
dest : '/www', //destination folder
exclusions : ['.sass-cache', '.git', 'images/src', 'node_modules', '.gitignore', '.ftppass', 'gruntfile.js', 'README.md', 'package.json'], //remember adding '.ftppass' to the exclusions in .gitignore if you are publishing the repo to github
// keep : ['blog','cv','projects'], // SUPER IMPORTANT! check what resources should STAY on the server, for example your wordpress installation or other subfolders you use for other projects. else they'll get wiped out
simple : false,
useList : false
}
}
});
// load npm tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-delete-sync');
grunt.loadNpmTasks('grunt-penthouse');
grunt.loadNpmTasks('grunt-ftpush');
// define default task
grunt.registerTask('default', ["browserSync", "watch"]);
};
强文
答案 0 :(得分:0)
尝试npm i -S pixrem
然后重试你的grunt命令。