我正在尝试通过在命令行中运行 npm install -g less
从 NPM 安装 Less。我检查了 install command 的文档:
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
“全局包”是什么意思?
最佳答案
您不需要全局安装 Less。
在本地安装它意味着该模块将仅可用于特定项目(您运行 npm install
时所在的目录),因为它安装到本地 node_modules
文件夹。
全局安装会将模块放入您的全局包文件夹(取决于操作系统),并允许您从任何地方运行包含的可执行命令。请注意,默认情况下,您只能在代码中使用本地包。
见 node.js docs有关全局与本地软件包的更多信息。
一般来说,您应该在本地安装大多数模块,除非它们提供您想在任何地方使用的 CLI 命令。
最后,我建议你全局安装 less,因为 less 提供了你在不同项目中可能需要的可执行命令。 This is also what the Less docs recommend .
关于node.js - "npm install -g"有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24606341/