how to Add my node_module, modules into package.json

前端 未结 4 2121
我在风中等你
我在风中等你 2021-02-19 07:42

I have some module in my node_module folder but because I am amateur in nodejs, when I wanted to install theme, I forgot to use --save with npm i

相关标签:
4条回答
  • 2021-02-19 08:22

    Its simple. Edit the package.json file and add the following for development dependencies:

    "devDependencies": {
        "broccoli-asset-rev": "^2.0.2",
        "broccoli-merge-trees": "^0.2.1",
        "broccoli-svg-sprite": "^1.0.3",
         ......
    }
    

    To get a list of package names and version numbers, you may look at node_modules/module folder/package.json for each of the modules to pick up the official package name and version. It will be of the form:

        {
      "name": "<<name of the package>>",
      "version": "2.1.0",
      "description": "broccoli asset revisions (fingerprint)",
    ....
    }
    

    just copy the name and version information from above into devDependencies into your project's package.json and you should be good to go.

    Also have a look here Is there a way to automatically build the package.json file for Node.js projects

    and here: https://docs.npmjs.com/files/package.json

    0 讨论(0)
  • 2021-02-19 08:32

    Already asked and well answered!

    Here're different ways suggested to create / maintain package.json file Is there a way to automatically build the package.json file for Node.js projects

    0 讨论(0)
  • 2021-02-19 08:34

    Simply change into the directory containing node_modules, backup any existing package.json in there, then use npm init to re-create the package.json.

    The generated package.json will include any modules that already exist within node_modules.

    Sample run:

    $ cd /my/project
    $ mv package.json package.json.bak # Backup package.json
    $ npm init                         # Recreate package.json with dependencies populated
    
    0 讨论(0)
  • 2021-02-19 08:43

    You can install the same package again using npm install --save <package> and it should just replace the current package files with freshly installed ones. It will also add the packages you already added with the default version notation.

    0 讨论(0)
提交回复
热议问题