[英]Why am I only able to run installed npm packages via npm run?
I have installed the less compiler ( lessc
) and stylelint ( stylelint
). 我已经安装了less编译器(
lessc
)和stylelint( stylelint
)。
I don't wish these to be installed globally, so they are in package.json
's dev dependencies section. 我不希望它们在全球范围内安装,因此它们位于
package.json
的dev依赖项部分。 I am only able to run them via npm run <some name here>
. 我只能通过
npm run <some name here>
来运行它们。 I'd like to be able to manually run them via simply typing lessc
as though it was globally installed. 我希望能够通过简单地键入
lessc
来手动运行它们,就像它是全局安装的一样。
"scripts": {
"lint": "stylelint ./src/**/*.less",
"compile": "lessc --help"
},
"devDependencies": {
"less": "^2.7.3",
"stylelint": "^8.3.1"
}
Having to tweak the compile
npm script everytime is not ideal, which is why I'd like the option of experimenting from the command line. 每次都必须调整npm
compile
脚本并不理想,这就是为什么我希望从命令行进行试验的原因。
I tried npm lessc --my-flags-here
but this is not a valid command. 我
npm lessc --my-flags-here
尝试了npm lessc --my-flags-here
但这不是有效的命令。 Is what I'd like to do possible, or will I have to stick to editing package.json every time? 我想做些什么,还是每次都必须坚持编辑package.json?
Since you installed them locally they aren't available globally, so in order to access them with using npm run
you'd need to reference the folder in which they are contained in the current project's directory. 由于它们是在本地安装的,因此它们在全球范围内不可用,因此,要使用
npm run
访问它们,您需要引用它们包含在当前项目目录中的文件夹。
Something like this would work: node_modules/.bin/lessc
这样的事情会起作用:
node_modules/.bin/lessc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.