Grunt:jit-grunt:找不到 "protractor" 任务的插件
Grunt: jit-grunt: Plugin for the "protractor" task not found
我是 yeoman/grunt/bower 的新手,我正在努力建立一个 angularjs 项目:
yo angular
我自己对 gruntfile 进行了一些更改,最近我发现量角器非常有用,我想将其添加到我的项目中。我在网上遵循了很多说明(比如这个 Integrating Protractor with Yeoman via Grunt 2 年前),但我仍然无法正确安装量角器。
这是我的Gruntfile.js
:(只显示了相关部分)
'use strict';
module.exports = function (grunt) {
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn'
});
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
yeoman: appConfig,
...
...
// Automatically inject Bower components into the app
wiredep: {
app: {
src: ['<%= yeoman.app %>/index.html'],
ignorePath: /\.\.\//
},
test: {
devDependencies: true,
src: '<%= karma.unit.configFile %>',
ignorePath: /\.\.\//,
fileTypes:{
js: {
block: /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
detect: {
js: /'(.*\.js)'/gi
},
replace: {
js: '\'{{filePath}}\','
}
}
}
},
sass: {
src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
...
...
// Test settings
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
protractor: {
options: {
keepalive: true,
configFile: 'protractor.conf.js'
},
run: {}
}
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'wiredep',
'concurrent:server',
'postcss:server',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'wiredep',
'concurrent:test',
'postcss',
'connect:test',
'karma',
'protractor:run'
]);
};
这是我的 package.json
:
{
"name": "Website",
"private": true,
"devDependencies": {
"autoprefixer-core": "^5.2.1",
"compass": "^0.1.1",
"grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.7",
"grunt-concurrent": "^1.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compass": "^1.0.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-cssmin": "^0.12.0",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-imagemin": "^1.0.0",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-uglify": "^0.7.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-filerev": "^2.1.2",
"grunt-google-cdn": "^0.4.3",
"grunt-jscs": "^1.8.0",
"grunt-karma": "^0.12.2",
"grunt-newer": "^1.1.0",
"grunt-ng-annotate": "^0.9.2",
"grunt-postcss": "^0.5.5",
"grunt-protractor-runner": "^3.0.0",
"grunt-svgmin": "^2.0.0",
"grunt-usemin": "^3.0.0",
"grunt-wiredep": "^2.0.0",
"jasmine-core": "^2.4.1",
"jit-grunt": "^0.9.1",
"jshint-stylish": "^1.0.0",
"karma": "^0.13.22",
"karma-jasmine": "^0.3.8",
"karma-phantomjs-launcher": "^1.0.0",
"karma2": "^0.13.22",
"phantomjs-prebuilt": "^2.1.7",
"protractor": "^3.0.0",
"time-grunt": "^1.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "karma start test/karma.conf.js",
"install": "node node_modules/protractor/bin/webdriver-manager update"
},
"dependencies": {}
}
我使用了 jit-grunt
(现在默认)所以它会为我加载这些插件。
我肯定已经安装了 protractor
和 grunt-protractor-runner
,遵循我上面提到的 post 和其他来源,例如 protractor
和 grunt-protractor-runner
的官方网站。在我本地 node_modules
:
$ ls node_modules/ | grep protractor
grunt-protractor-runner
protractor
但无论我做什么,我仍然收到来自 grunt 的错误:
$ grunt protractor
jit-grunt: Plugin for the "protractor" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "protractor" failed. Use --force to continue.
和运行 grunt 测试:
$ grunt test
Running "clean:server" (clean) task
>> 1 path cleaned.
...
...
Running "karma:unit" (karma) task
01 05 2016 15:03:51.048:WARN [watcher]: Pattern
01 05 2016 15:03:51.094:INFO [karma]: Karma v0.13.22 server started at http://localhost:8080/
01 05 2016 15:03:51.112:INFO [launcher]: Starting browser PhantomJS
01 05 2016 15:03:52.259:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#68w8QMUehAm8AAf2AAAA with id 17032121
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 2 of 2 SUCCESS (0.003 secs / 0.026 secs)
jit-grunt: Plugin for the "protractor" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "protractor:run" failed. Use --force to continue.
Aborted due to warnings.
有什么我遗漏的吗?我已经坚持了好几天了。非常感谢任何帮助。
感谢@theaccordance 的建议和提示。结果 JIT-grunt
可能在加载 grunt-protractor-runner
时遇到一些困难。
在 Gruntfile.js 中添加 grunt.loadNpmTasks('grunt-protractor-runner');
将解决问题。
接受的答案遵循反模式并违背了 Grunt 的 JIT(及时)插件加载器的目的。
jit-grunt
的目标是自动加载所需的插件,从而使 grunt.loadNpmTasks
的使用过时。
jit-grunt
的 documentation 解释了插件加载程序如何寻找插件:
Will automatically search for the plugin from the task name. Search in
the following order:
- node_modules/grunt-contrib-task-name
- node_modules/grunt-task-name
- node_modules/task-name
因为你有一个任务protractor
,插件加载器将尝试按以下顺序找到相应的插件:
grunt-contrib-protractor
- 不存在于
packages.json
grunt-protractor
- 不存在于
packages.json
protractor
- 发现于
packages.json
!
- 遗憾的是不匹配
- 任务
protractor
所需的插件是 grunt-protractor-runner
在这种情况下,我们可以设置静态映射,如错误消息所指出的那样。我们以格式 taskname
: grunt_plugin_name
:
// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn',
<strong>protractor: 'grunt-protractor-runner'</strong>
});
这是一个老问题,希望我的回答能帮助到其他遇到这个问题的人。
我是 yeoman/grunt/bower 的新手,我正在努力建立一个 angularjs 项目:
yo angular
我自己对 gruntfile 进行了一些更改,最近我发现量角器非常有用,我想将其添加到我的项目中。我在网上遵循了很多说明(比如这个 Integrating Protractor with Yeoman via Grunt 2 年前),但我仍然无法正确安装量角器。
这是我的Gruntfile.js
:(只显示了相关部分)
'use strict';
module.exports = function (grunt) {
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn'
});
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
yeoman: appConfig,
...
...
// Automatically inject Bower components into the app
wiredep: {
app: {
src: ['<%= yeoman.app %>/index.html'],
ignorePath: /\.\.\//
},
test: {
devDependencies: true,
src: '<%= karma.unit.configFile %>',
ignorePath: /\.\.\//,
fileTypes:{
js: {
block: /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
detect: {
js: /'(.*\.js)'/gi
},
replace: {
js: '\'{{filePath}}\','
}
}
}
},
sass: {
src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
...
...
// Test settings
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
protractor: {
options: {
keepalive: true,
configFile: 'protractor.conf.js'
},
run: {}
}
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'wiredep',
'concurrent:server',
'postcss:server',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'wiredep',
'concurrent:test',
'postcss',
'connect:test',
'karma',
'protractor:run'
]);
};
这是我的 package.json
:
{
"name": "Website",
"private": true,
"devDependencies": {
"autoprefixer-core": "^5.2.1",
"compass": "^0.1.1",
"grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.7",
"grunt-concurrent": "^1.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compass": "^1.0.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-cssmin": "^0.12.0",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-imagemin": "^1.0.0",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-uglify": "^0.7.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-filerev": "^2.1.2",
"grunt-google-cdn": "^0.4.3",
"grunt-jscs": "^1.8.0",
"grunt-karma": "^0.12.2",
"grunt-newer": "^1.1.0",
"grunt-ng-annotate": "^0.9.2",
"grunt-postcss": "^0.5.5",
"grunt-protractor-runner": "^3.0.0",
"grunt-svgmin": "^2.0.0",
"grunt-usemin": "^3.0.0",
"grunt-wiredep": "^2.0.0",
"jasmine-core": "^2.4.1",
"jit-grunt": "^0.9.1",
"jshint-stylish": "^1.0.0",
"karma": "^0.13.22",
"karma-jasmine": "^0.3.8",
"karma-phantomjs-launcher": "^1.0.0",
"karma2": "^0.13.22",
"phantomjs-prebuilt": "^2.1.7",
"protractor": "^3.0.0",
"time-grunt": "^1.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "karma start test/karma.conf.js",
"install": "node node_modules/protractor/bin/webdriver-manager update"
},
"dependencies": {}
}
我使用了 jit-grunt
(现在默认)所以它会为我加载这些插件。
我肯定已经安装了 protractor
和 grunt-protractor-runner
,遵循我上面提到的 post 和其他来源,例如 protractor
和 grunt-protractor-runner
的官方网站。在我本地 node_modules
:
$ ls node_modules/ | grep protractor
grunt-protractor-runner
protractor
但无论我做什么,我仍然收到来自 grunt 的错误:
$ grunt protractor
jit-grunt: Plugin for the "protractor" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "protractor" failed. Use --force to continue.
和运行 grunt 测试:
$ grunt test
Running "clean:server" (clean) task
>> 1 path cleaned.
...
...
Running "karma:unit" (karma) task
01 05 2016 15:03:51.048:WARN [watcher]: Pattern
01 05 2016 15:03:51.094:INFO [karma]: Karma v0.13.22 server started at http://localhost:8080/
01 05 2016 15:03:51.112:INFO [launcher]: Starting browser PhantomJS
01 05 2016 15:03:52.259:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#68w8QMUehAm8AAf2AAAA with id 17032121
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 2 of 2 SUCCESS (0.003 secs / 0.026 secs)
jit-grunt: Plugin for the "protractor" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "protractor:run" failed. Use --force to continue.
Aborted due to warnings.
有什么我遗漏的吗?我已经坚持了好几天了。非常感谢任何帮助。
感谢@theaccordance 的建议和提示。结果 JIT-grunt
可能在加载 grunt-protractor-runner
时遇到一些困难。
在 Gruntfile.js 中添加 grunt.loadNpmTasks('grunt-protractor-runner');
将解决问题。
接受的答案遵循反模式并违背了 Grunt 的 JIT(及时)插件加载器的目的。
jit-grunt
的目标是自动加载所需的插件,从而使 grunt.loadNpmTasks
的使用过时。
jit-grunt
的 documentation 解释了插件加载程序如何寻找插件:
Will automatically search for the plugin from the task name. Search in the following order:
- node_modules/grunt-contrib-task-name
- node_modules/grunt-task-name
- node_modules/task-name
因为你有一个任务protractor
,插件加载器将尝试按以下顺序找到相应的插件:
grunt-contrib-protractor
- 不存在于
packages.json
- 不存在于
grunt-protractor
- 不存在于
packages.json
- 不存在于
protractor
- 发现于
packages.json
! - 遗憾的是不匹配
- 任务
protractor
所需的插件是grunt-protractor-runner
- 发现于
在这种情况下,我们可以设置静态映射,如错误消息所指出的那样。我们以格式 taskname
: grunt_plugin_name
:
// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn',
<strong>protractor: 'grunt-protractor-runner'</strong>
});
这是一个老问题,希望我的回答能帮助到其他遇到这个问题的人。