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

I deleted package.json and Gruntfile.js and now Grunt will not load dependencies

本文关键字:Grunt 现在 加载 依赖 js 删除 package json Gruntfile      更新时间:2024-04-28

因此,我意外地从项目目录中删除了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,但我是否应该运行上面的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不在我的项目文件夹中。。哇!哈哈。问题解决了。

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

npm install

您可能必须以管理员权限打开命令提示符才能正常工作。

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