[英]Ignore “Local NPM module not found” warning in Grunt
I'm using matchdep to read dependencies from my package.json
file into grunt
. 我正在使用matchdep将
package.json
文件中的依赖项读取到grunt
。
require('matchdep').filterAll('grunt-*').forEach(grunt.loadNpmTasks);
I have my dependencies split between dependencies
(for everyone) and devDependencies
(for front-end developers.) 我的依赖项分为
dependencies
(适用于每个人)和devDependencies
(适用于前端开发人员)。
Our back-end devs will run the following to get a build of the static assets without requiring jasmine, phantomJS, etc (things that will be run by front-end devs and the CI server) 我们的后端开发人员将运行以下内容以构建静态资产,而无需茉莉花,phantomJS等(这些内容将由前端开发人员和CI服务器运行)
$ npm install --production
$ grunt build
However, when using the --production
build, grunt.loadNpmTasks()
will emit a warning for any missing packages. 但是,当使用
--production
版本时, grunt.loadNpmTasks()
将针对任何缺少的软件包发出警告。
>> Local Npm module "grunt-contrib-watch" not found. Is it installed?
Is there a way to supress this warning? 有没有办法抑制这个警告?
You have to question why your "back-end devs" would have to actually build your package - put otherwise, why do they need grunt but NOT devDependencies. 您必须质疑为什么您的“后端开发人员”必须实际构建您的软件包-否则,为什么他们需要笨拙而不需要devDependencies。 This is kind of backwards (requiring users to build your package is certainly an anti-pattern).
这是一种倒退(要求用户构建您的软件包肯定是一种反模式)。
That being said, using matchdep, you can / should use: 话虽这么说,使用matchdep,您可以/应该使用:
require('matchdep').filter
inside your "production" target require('matchdep').filter
require('matchdep').filterAll
inside your "development" target require('matchdep').filterAll
在“开发”目标中 Certainly, that would require you to specialize your grunt build
(eg: have grunt builddev
and grunt buildproduction
- or maybe use environment variables) - but again, see above... 当然,这将需要您专门化
grunt build
(例如:使用grunt builddev
和grunt buildproduction
或使用环境变量)-但同样,请参见上文...
You can use CLI flags to pass options into grunt. 您可以使用CLI标志将选项传递给grunt。 For consistency, I am using a
--production
flag, just as I do with npm. 为了保持一致性,我使用
--production
标志,就像使用npm一样。
So, from the CLI: 因此,从CLI:
$ grunt build --production
And then in the Gruntfile: 然后在Gruntfile中:
var dependencies;
// test for the production flag
if (grunt.option('production')) {
// scan dependencies but ignore dev
dependencies = require('matchdep').filter('grunt-*');
} else {
// scan all dependencies
dependencies = require('matchdep').filterAll('grunt-*');
}
// load only relevant dependencies
dependencies.forEach(grunt.loadNpmTasks);
This is done at the top of the module before any custom tasks are registered. 这是在注册任何自定义任务之前在模块顶部完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.