简体   繁体   English

忽略Grunt中的“找不到本地NPM模块”警告

[英]Ignore “Local NPM module not found” warning in Grunt

I'm using matchdep to read dependencies from my package.json file into grunt . 我正在使用matchdeppackage.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 builddevgrunt 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.

相关问题 Grunt-找不到npm模块 - Grunt - npm module not found 未找到本地 Npm 模块“grunt-legacy-util”。 是否已安装? - Local Npm module “grunt-legacy-util” not found. Is it installed? 找不到本地Npm模块“ grunt-template-jasmine-istanbul” - Local Npm module “grunt-template-jasmine-istanbul” not found 找不到本地npm模块“ grunt-prettify”。 安装好了吗? - local npm module “grunt-prettify” not found. is it installed? 找不到本地Npm模块“ grunt-parallel”。 安装好了吗? - Local Npm module “grunt-parallel” not found. Is it installed? 找不到本地Npm模块“ GRUNT-PLUGIN-MODULE”。 安装好了吗? 是什么原因造成的? - Local Npm module “GRUNT-PLUGIN-MODULE” not found. Is it installed? What's causing this? 使用angular-gettext时,找不到本地Npm模块“ grunt-angular-gettext”错误 - Local Npm module “grunt-angular-gettext” not found error when using angular-gettext 咕噜声 - 得到“本地Npm模块”xxx“未找到。它安装了吗?“造成这种情况的原因是什么? - grunt - getting “Local Npm module ”xxx“ not found. Is it installed?” What's causing this? 未找到Npm模块“grunt-contrib-imagemin”,是否已安装? - Npm module “grunt-contrib-imagemin” not found, Is it installed? 没有找到Npm模块“grunt-sass”。它安装了吗? - Npm module “grunt-sass” not found. Is it installed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM