How to replace NPM node_module folder with another folder?

前端 未结 1 471
清歌不尽
清歌不尽 2021-02-15 05:00

By default of NPM is installing the modules under \"node_modules\". Is there a way to change it to be for example \"my_modules?

1条回答
  •  粉色の甜心
    2021-02-15 05:44

    The standard for all node modules is to use the node_modules directory.

    Do not try to go against this uniform standard.

    What are you trying to accomplish by customizing the directory?


    Note:

    The following command will install a module to my_project/node_modules/some_module

    [~/my_project] $ npm install some_module
    

    If you'd like to install modules and have them globally available on your system, you can use the --global (-g) flag

    [~/my_project] $ npm install -g some_module
    

    Packages installed with the -g flag are installed to ~/.npm


    EDIT

    Per your comment, you can attempt to install any directory that contains a package.json file

    [~/my_project] $ npm install /path/to/my/pkg
    

    Alternatively you can install a symbolic link instead of copying the entire module to your ~/my_project/node_modules directory.

    [~/my_project] $ npm link /path/to/my/pkg
    

    For more info about this:

    $ npm help install
    $ npm help link
    

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