简体   繁体   English

如何在Windows上使用单个NPM命令运行多个NPM命令

[英]How can I run multiple NPM commands with a single NPM Command on Windows

I am setting a package.json file that will start Nodemon, run my watch css command and run browser sync all with the "npm start" command. 我正在设置一个package.json文件,该文件将启动Nodemon,运行watch css命令并使用“ npm start”命令运行所有浏览器同步。

This works on my Mac computer at work but does not work on my Windows computer at home. 这可以在我的Mac计算机上工作,但不能在我的Windows计算机上工作。

On my Mac, it will listen for any changes to server and SCSS files and also run browser sync. 在我的Mac上,它将侦听服务器和SCSS文件的所有更改,并运行浏览器同步。

On Windows it only runs Nodemon and just waits for any server changes. 在Windows上,它仅运行Nodemon,并等待任何服务器更改。 It looks like it ignores my other two commands. 看起来它忽略了我的其他两个命令。

Do I need to do something different for Windows? 我需要为Windows做些不同的事情吗? Ideally I would like the code to work universally on both platforms. 理想情况下,我希望代码可以在两个平台上通用。

Nodemon seems to be the problem here because watch-css css and browsersync work but anything after nodemon does not work. Nodemon似乎是这里的问题,因为watch-css css和browsersync可以工作,但是nodemon之后的任何工作都不起作用。

"scripts": {
  "build-css": "node-sass --output-style compressed --source-map true -o public/css scss",
  "watch-css": "nodemon -e scss -x \"npm run build-css\"",
  "build-js": "browserify js/app.js -o public/js/app.js",
  "browser-sync": "browser-sync start --port 4000 --proxy 'localhost:3000' --files 'views/*' 'public/**/*' --no-notify",
  "start": "nodemon ./bin/www & npm run watch-css & npm run browser-sync"
},

Here's what I use: npm-run-all (this is cross-platform). 这是我使用的: npm-run-all (这是跨平台的)。 They allow you to run your processes/commands parallelly and sequentially ( -p or -s ). 它们允许您并行和顺序( -p-s )运行进程/命令。

"scripts": {
    "build-css": "node-sass-chokidar src/ -o src/ --importer=node_modules/node-sass-tilde-importer",
    "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    // ... and much more
}

This is working fine for me in both windows and mac. 对于Windows和Mac,这对我来说都很好。 Try it, hope this is helpful. 尝试一下,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM