“El Capitan”是否无根地打破了旧的 grunt 配置?
Is 'El Capitan's' rootless breaking old grunt configs?
迁移到 El Capitan 后,用户似乎遇到了 grunt 安装问题,这可能与 El Capitan 的无根更改有关。特别是,运行 grunt --force 命令会导致 EPERM 错误。工作流程如下:
假设已安装 npm,使用 package.json 和 gruntfile.js 导航到 grunt 目录并调用 grunt:
grunt --force
示例 Gruntfile.js 文件内容:
module.exports = function(grunt) {
// All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
// Configuration for concatenating files goes here.
dist: {
src: [
'../js/libs/owl.carousel.js',
'../js/libs/jquery.actual.js',
'../js/libs/chosen.jquery.js',
'../js/libs/jquery.parallax.js',
'../js/src/common.js'
],
dest: '../js/pro/global.js',
},
},
uglify: {
build: {
src: '../js/pro/global.js',
dest: '../js/pro/global.min.js',
},
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '../img/src/',
src: ['**/*.{png,jpg,gif}'],
dest: '../img/pro/'
}]
}
},
compass: {
dev: {
options: {
sassDir: '../sass',
cssDir: '../css',
fontsDir: '../fonts',
imagesDir: '../img/',
images: '../img/',
javascriptsDir: '../js/pro',
//environment: 'development',
outputStyle: 'compressed',
relativeAssets: true,
httpPath: '.',
}
},
},
watch: {
scripts: {
files: ['../js/**/**.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: true,
},
},
images: {
files: ['../img/src/**.{png,jpg,gif}'],
tasks: ['imagemin'],
options: {
spawn: true,
}
},
compass: {
files: ['../**/*.{scss,sass}'],
tasks: ['compass:dev'],
}
},
svgstore: {
defaults: {
options: {
prefix : 'icon-',
},
files: {
'../img/svg-defs.svg': ['../img/svg/*.svg']
}
}
},
});
// Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-svgstore');
// Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'uglify', /*'imagemin',*/ 'compass', 'svgstore', 'watch']);
};
示例 package.json 文件内容:
{
"name": "Call Me Maybe",
"version": "0.2.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-compass": "^1.0.4",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-imagemin": "^0.9.4",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "^0.9.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-svgstore": "^0.5.0"
}
}
产生的EPERM错误如下:
Running "concat:dist" (concat) task
Warning: Unable to write "../js/pro/global.js" file (Error code: EPERM). Used --force, continuing.
Running "uglify:build" (uglify) task
Warning: Unable to write "../js/pro/global.min.js" file (Error code: EPERM). Used --force, continuing.
Running "compass:dev" (compass) task
Warning: Command failed: /bin/sh: compass: command not found. Used --force, continuing.
Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
Running "svgstore:defaults" (svgstore) task
Warning: Unable to write "../img/svg-defs.svg" file (Error code: EPERM). Used --force, continuing.
Running "watch" task
Waiting...
有趣的是,Ruby 和 Compass 也安装了,所以它确实符合无根无法写入文件夹问题的理论,但是如何将依赖核心移动到其他地方(即 /usr/local/bin)所以这不是问题?
在 El Capitan Betas 期间,一些用户建议通过终端启用 root - 虽然这似乎不再有效,因为错误仍然存在并且 /usr/bin 文件夹仍然不允许更改权限。
在 /usr/bin 上安装非系统软件是一个糟糕的举动,现在在 El Capitan 中被禁止,并且有充分的理由。
我不熟悉 grunt,但如果你能开始使用 /usr/local/bin,那么可能一切正常。
对于那些 运行 进入相同问题的人,我不得不消除使用安装到路径的二进制文件:/usr/bin,并在更新路径 /usr/local/bin 后重新安装。 Ruby 往往是罪魁祸首。因为我一直在努力寻找我所有的 ruby 安装,所以我最终安装了 rbenv 来管理我的 ruby 版本。
以下终端命令可能有助于识别有问题的路径:
which ruby
gem environment
gem uninstall [insert gem name here]
[google how to set your paths to /usr/local/bin... (will be in a hidden file)]
gem install [insert gem name here]
迁移到 El Capitan 后,用户似乎遇到了 grunt 安装问题,这可能与 El Capitan 的无根更改有关。特别是,运行 grunt --force 命令会导致 EPERM 错误。工作流程如下:
假设已安装 npm,使用 package.json 和 gruntfile.js 导航到 grunt 目录并调用 grunt:
grunt --force
示例 Gruntfile.js 文件内容:
module.exports = function(grunt) { // All configuration goes here grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), concat: { // Configuration for concatenating files goes here. dist: { src: [ '../js/libs/owl.carousel.js', '../js/libs/jquery.actual.js', '../js/libs/chosen.jquery.js', '../js/libs/jquery.parallax.js', '../js/src/common.js' ], dest: '../js/pro/global.js', }, }, uglify: { build: { src: '../js/pro/global.js', dest: '../js/pro/global.min.js', }, }, imagemin: { dynamic: { files: [{ expand: true, cwd: '../img/src/', src: ['**/*.{png,jpg,gif}'], dest: '../img/pro/' }] } }, compass: { dev: { options: { sassDir: '../sass', cssDir: '../css', fontsDir: '../fonts', imagesDir: '../img/', images: '../img/', javascriptsDir: '../js/pro', //environment: 'development', outputStyle: 'compressed', relativeAssets: true, httpPath: '.', } }, }, watch: { scripts: { files: ['../js/**/**.js'], tasks: ['concat', 'uglify'], options: { spawn: true, }, }, images: { files: ['../img/src/**.{png,jpg,gif}'], tasks: ['imagemin'], options: { spawn: true, } }, compass: { files: ['../**/*.{scss,sass}'], tasks: ['compass:dev'], } }, svgstore: { defaults: { options: { prefix : 'icon-', }, files: { '../img/svg-defs.svg': ['../img/svg/*.svg'] } } }, }); // Where we tell Grunt we plan to use this plug-in. grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-imagemin'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-compass'); grunt.loadNpmTasks('grunt-svgstore'); // Where we tell Grunt what to do when we type "grunt" into the terminal. grunt.registerTask('default', ['concat', 'uglify', /*'imagemin',*/ 'compass', 'svgstore', 'watch']); };
示例 package.json 文件内容:
{
"name": "Call Me Maybe",
"version": "0.2.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-compass": "^1.0.4",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-imagemin": "^0.9.4",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "^0.9.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-svgstore": "^0.5.0"
}
}
产生的EPERM错误如下:
Running "concat:dist" (concat) task
Warning: Unable to write "../js/pro/global.js" file (Error code: EPERM). Used --force, continuing.
Running "uglify:build" (uglify) task
Warning: Unable to write "../js/pro/global.min.js" file (Error code: EPERM). Used --force, continuing.
Running "compass:dev" (compass) task
Warning: Command failed: /bin/sh: compass: command not found. Used --force, continuing.
Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
Running "svgstore:defaults" (svgstore) task
Warning: Unable to write "../img/svg-defs.svg" file (Error code: EPERM). Used --force, continuing.
Running "watch" task
Waiting...
有趣的是,Ruby 和 Compass 也安装了,所以它确实符合无根无法写入文件夹问题的理论,但是如何将依赖核心移动到其他地方(即 /usr/local/bin)所以这不是问题?
在 El Capitan Betas 期间,一些用户建议通过终端启用 root - 虽然这似乎不再有效,因为错误仍然存在并且 /usr/bin 文件夹仍然不允许更改权限。
在 /usr/bin 上安装非系统软件是一个糟糕的举动,现在在 El Capitan 中被禁止,并且有充分的理由。
我不熟悉 grunt,但如果你能开始使用 /usr/local/bin,那么可能一切正常。
对于那些 运行 进入相同问题的人,我不得不消除使用安装到路径的二进制文件:/usr/bin,并在更新路径 /usr/local/bin 后重新安装。 Ruby 往往是罪魁祸首。因为我一直在努力寻找我所有的 ruby 安装,所以我最终安装了 rbenv 来管理我的 ruby 版本。
以下终端命令可能有助于识别有问题的路径:
which ruby
gem environment
gem uninstall [insert gem name here]
[google how to set your paths to /usr/local/bin... (will be in a hidden file)]
gem install [insert gem name here]