有一些自带命令的辅助开发、测试类的工具,官方都推荐全局安装,如果不想全局安装只想在某个项目下用该怎么办呢?
如http-server、browser-sync、webpack这种自带CLI的工具
使用命令运行会报错,如下,

$ http-server
bash: http-server: command not found

$ browser-sync
bash: browser-sync: command not found

$ webpack
bash: webpack: command not found

上面提示我们找不到这个命令


解决1:直接使用下面方式运行

$ ./node_modules/.bin/http-server -c-1 -o

$ ./node_modules/.bin/browser-sync start --server --files "*"

$ ./node_modules/.bin/webpack



解决2:在 package.json里面的"scripts"对象里面添加 ``` "scripts": { "xxx": "http-server", "xxx": "browser-sync start --server --files \"*\"", "xxx": "webpack" } ``` ``` npm run xxx ```


解决3:在 package.json里面的"scripts"对象里面添加 ``` "scripts": { "start": "http-server", "start": "browser-sync start --server --files \"*\"", "start": "webpack" } ``` ``` npm start ```

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2021-06-14
  • 2022-12-23
  • 2021-11-15
  • 2021-07-25
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-12-26
  • 2022-12-23
  • 2018-04-03
  • 2022-02-22
相关资源
相似解决方案