我的grunt文件在我的MacBook Pro上本地运行成功,但在我的Ubuntu Plesk服务器上没有运行,不确定是什么问题。非常感谢你的帮助。
我已经注释掉了一个引用巨型图像库的部分,并在dropbox images.tar.gz附加了一个小图像目录
在终端解压缩:
tar -zxvf images.tar.gz
如何删除OSX生成的恼人的._文件:
root @ vs1:/ images#查找。 -iname' ._ *' -exec rm -rf {} \;
我收到以下错误消息:
运行" imagemin:dynamic" (imagemin)任务 警告:错误:错误:写EPIPE / var / www / vhosts / staging.specialistreferrals.co.nz / httpdocs / node_modules / jpegtran-bin / vendor / jpegtran:1:/var/www/vhosts/staging.specialistreferrals.co。 nz / httpdocs / node_modules / jpegtran-bin / vendor / jpegtran:语法错误:"("意外 在文件images / CM_logo.jpg中使用--force继续。
还尝试过获取最新版本的grunt-contrib-imagemin。
为此我做了
npm uninstall --save-dev grunt-contrib-imagemin
然后
npm install --save-dev grunt-contrib-imagemin
Grunt文件代码:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// minifying .js files
uglify: {
my_target: {
files: [{
// javascript folder
expand: true,
cwd: 'js/',
src: ['*.js'],
dest: 'js/js_opt/',
ext: '.min.js'
},
{
// slimbox folder
src: ['slimbox-2.05/js/slimbox2.js'],
dest: 'slimbox-2.05/js/slimbox2.min.js'
}]
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'images/',
src: ['*.{jpg,png,gif}'],
dest: 'images_opt/'
// },
// {
// expand: true,
// cwd: 'SR_images/',
// src: ['*.{jpg,png,gif}'],
// dest: 'SR_images_opt/'
}]
}
},
cssmin: {
target: {
files: [{
// css folder
expand: true,
cwd: 'css/',
src: ['*.css', '!*.min.css'],
dest: 'css/css_opt/',
ext: '.min.css'
},
{
// jquery folder
expand: true,
cwd: 'js/jquery-1.10.4/',
src: ['*.css', '!*.min.css'],
dest: 'js/jquery-1.10.4/',
ext: '.min.css'
},
{
// slimbox folder
expand: true,
cwd: 'slimbox-2.05/css/',
src: ['*.css'],
dest: 'slimbox-2.05/css/',
ext: '.min.css'
},
{
// fancybox folder
expand: true,
cwd: 'js/fancybox/source/',
src: ['*.css'],
dest: 'js/fancybox/source/',
ext: '.min.css'
}],
}
},
watch: {
scripts: {
files: 'js/*.js',
tasks: ['uglify'],
},
images: {
files: ['images/*.{jpg,png,gif}'],
tasks: ['imagemin'],
},
css: {
files: 'css/*.css',
tasks: ['cssmin'],
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task(s).
grunt.registerTask('default', ['uglify', 'imagemin', 'cssmin', 'watch']);
};
答案 0 :(得分:0)
通过卸载节点然后使用chris-lea / node.js存储库来修复
$ cd /
$ sudo apt-get remove nodejs
安装nodejs,npm和grunt-cli
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo npm install -g grunt-cli
在项目目录中安装grunt
$ cd ~/myproject
$ echo "{}" > package.json
$ npm install grunt --save-dev
验证grunt已安装
$ nodejs --version
v0.10.33
$ npm --version
1.4.28
$ grunt --version
grunt-cli v0.1.13
grunt v0.4.5
运行简单的grunt任务
$ cd ~/myproject
创建一个package.json文件:
{
"name": "SR",
"version": "0.1.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-imagemin": "^0.9.4",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "^0.6.1"
}
}