我删除了package.json和Gruntfile.js,现在Grunt不会加载依赖项

时间:2016-04-12 01:43:14

标签: javascript json node.js powershell gruntjs

所以我偶然从我的项目目录中删除了我的package.json和Gruntfile文件夹,在我这样做之前我已经运行了gruntgrunt jshint,它运行得很好。我重新制作了两个文件(package.json和Gruntfile.js),现在当我尝试运行gruntgrunt jshint它告诉我..

PS C:\Users\Vincent\desktop\projects\kittenbook> grunt jshint
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-contrib-jshint" not found. Is it installed?
Warning: Task "jshint" not found. Use --force to continue.

然后Powershell很快就崩溃了。

Npm工作我已经检查过,我知道Grunt显然已安装。

这是我必须重新制作的Gruntfile.js。在我删除package.json文件之前,它运行得很好。

module.exports = function(grunt) {
    grunt.initConfig({
        concat: {
        release: {
            src: ['js/values.js', 'js/prompt.js'],
            dest: 'release/main.js'
        }
      },
      copy: {
          release: {
              src: 'manifest.json',
              dest: 'release/manifest.json'
          }
      },
      jshint: {
          files: ['js/values.js', 'js/prompt.js']
      }
    });

    // Load Grunt plugin
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-jshint');

    // Register tasks
    grunt.registerTask('default', ['jshint', 'concat', 'copy']);

};

这是新的package.json文件

{
  "name": "kittenbook",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-concat": "^0.3.0",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-jshint": "^0.6.5",
    "grunt-contrib-watch": "^1.0.0"
  }

}

即使我第一次运行它,我也应该运行Gruntfile吗?这会弄得一团糟吗?

我希望这不会太混乱。我是编程新手。谢谢!

更新:当我尝试运行npm install

PS C:\Users\Vincent> cd desktop/projects/kittenbook
PS C:\Users\Vincent\desktop\projects\kittenbook> npm install
npm WARN package.json kittenbook@1.0.0 No description
npm WARN package.json kittenbook@1.0.0 No repository field.
npm WARN package.json kittenbook@1.0.0 No README data
npm WARN package.json kittenbook@1.0.0 No license field.

更新:我犯的错误是Gruntfile.js在我的项目文件夹之外..哇..哈哈。问题解决了。

1 个答案:

答案 0 :(得分:2)

在命令提示符下,转到项目目录并运行以下命令。

npm install

您可能必须使用管理员权限打开命令提示符才能生效。

这将安装package.json文件中定义的所有npm模块。