How do I prevent browser-sync from opening a new browser tab when I run it via npm scripts? - browser-sync

I'm wanting to start browser-sync from an npm script.
At the moment when I do this, browser-sync opens a new browser tab.
That's a cool feature. But I don't want this to happen all the time.
I've tried using the parameter '--open false' to the command, but the w
This is the command that I'm using at the moment:
browser-sync start --server dist --files 'dist/** --open false'

Related

There is no response when starting React, including "npm start" and "npm run start"

I downloaded (git clone) 2 git repo, one of which is a React project. If I start it with the command npm start or npm run start, the terminal will stop at the last line and nothing happens:
> meetjobs#0.1.0 start
> PORT=3000 node server.js
Warning: React.createFactory() is deprecated and will be removed in a future major release. Consider using JSX or use React.createElement() directly instead.
listening on 3000...
I used the npm run start-reactapp command to successfully start the React website of the same PC (Win10), but now it only automatically opens the browser window, and shows the "localhost refused to connect" error.
Please tell me what I have overlooked.

Nodemon aequivalent to npm run dev

I've just started using the whole javascript and node.js environment. To start an existing project I run three commands
npm install, npm run all and finally npm run dev to start the application in my browser.
Now, whenever I update the code I stop the current running dev via Ctrl+C, press arrow up key to get npm run dev in my terminal again and hit Enter. I believe there is a better way of doing this repetitive task, like Nodemon.
But, what is the aequivalent command for that, so that the updates I make in the code automatically become visible in the browser?
I have three files which do not work with nodeman: package.json, Gruntfile.js, app/index.js. Moreover, I tried nodemon --exec npm run dev which permanently does sth, but does not start my application.
Do you have any suggestions?
Yes, I would look at the --exec flag on nodemon. You could do something like:
nodemon --exec npm run dev
This will run npm run dev every time a source file changes. Read the nodemon NPM page to get a better idea of how to use it.

I can't open Cypress

I install node js and visual studio code , Create a folder and open cmd
Input npm init
Input npm install cypress and wait to complete
I open Visual studio code and run command:
" ./node_modules/.bin/cypress open "
But nothing is happened. Cypress can't open.
I tried with other way as use : npm run cypress:open but it's not open too.
I run on Window 10, node js 8.12, visual studio code ver 1.27.2
In other PC which cypress worked normally with Windows PowerShell in terminal but in error PC it only run with cmd.
Use \ instead of / in path for Windows:
.\node_modules\.bin\cypress open
In order to run cypress by this comand npm run cypress:open you need to add "cypress:open": "cypress open" to the scripts field in your package.json file:
{
"scripts": {
"cypress:open": "cypress open"
}
}
Add below code of line in package.json file
{
"scripts": {
"test": "cypress open"
}
}
and run cypress thro' editor command prompt using below command prompt
npm run test
Navigate to your project path
cd /your/project/path
Install Cypress using npm
npm install cypress --save-dev
In package.json file add below line inside scripts
"scripts": {"cypress:open": "cypress open"}
In terminal enter command
npm run cypress:open
Then a cypress window opens with example tests.
Cypress Open Error- Solution for first time installer in Windows 10
A restart is required if you are trying to do it for the first time.
Execute the command .\node_modules.bin\cypress open
PS C:\Users\Ashwini Sambandan\cypressautomation> node_modules.bin\cypress open
It looks like this is your first time using Cypress: 3.8.3
√ Verified Cypress! C:\Users\Ashwini Sambandan\AppData\Local\Cypress\Cache\3.8.3\Cypress
Opening Cypress...
I hope you must find a solution for this. But there is no accepted answer so I to add one that worked for me.
It happens when you run cypress for the very first time.
Search for cypress.json or ctrl + p then type cypress.json.
Paste this in it.
{
"chromeWebSecurity": false,
"hosts": {
"*.localhost": "127.0.0.1"
}
}
Then try npm run cypress open or npx cypress open
It's a bit unclear what you're trying to do in step 4. Do you run the Cypress command from VS code terminal? If so, make sure you're in the correct location. Then run your Cypress start command. It should work.
If you are in the correct location and still doesn't work, you can also try:
npx cypress open works like a charm in my environment and requires npm#5.2.0 or greater. Let me know your progress.
https://docs.cypress.io/guides/getting-started/installing-cypress.html#Opening-Cypress

'grunt watch' won't run from a package.json script on Windows

I am doing a dev run of a small node app on a Windows machine. I have set up grunt-contrib-watch and can run it successfully from the bash command line by typing 'grunt watch'. It works as expected.
However when I run the following script in my package.json file:
"scripts": {
"start": "node app",
"predev": "grunt",
"dev": "start http://localhost:3000 & node-dev app & grunt watch"
}
...and start the app using 'npm run dev' a new browser tab opens successfully and the app runs on port 3000 as expected, however 'grunt watch' does not run. I can open a new bash window and run 'grunt watch' separately and it works successfully. I can also automate opening the browser window and then running 'grunt watch' successfully, but it seems that I cannot start up the server AND run grunt from the same bash window - is this a known issue in Windows?
When chaining different command with & commands are executed one after the other. That mean that in your configuration the & node-dev app & grunt watch commands will be executed only once you close the server.
To execute different command in parallel in my build I use the parallelshell module... I'm not sure how stable it is though but it seems to work for me. There is probably other more suitable solution.
link to the npm page of parallelshell : https://www.npmjs.com/package/parallelshell

Create WebStorm run configurations from package.json "scripts" section

In my package.json file, I have the following "scripts" configuration.
...
"scripts": {
"start": "watchify -o lib/index.js -v -d .",
"build": "browserify . | uglifyjs -cm > lib/index.js",
"test": "jest"
}
...
This allows me to run npm start, npm build and npm test from the command line.
This is great! But ideally, I would like to be able to run those tasks from within WebStorm using run configurations, due to how convenient the interface is. I have not been able to figure out how to do this.
Is there a way to create my own custom run configurations or automatically generate them from my package.json?
you can use Node.js Run configuration for this. For example, for 'npm start':
Working dir: /path/to/your/package.json
JavaScript file: /path/to/global/node_modules/npm/bin/npm-cli.js
Application parameters: run start
To find the global node_modules path from the command line use "npm root -g".
There is no way to auto-create run configurations from files. And the only way to create your own run configuration is developing a plugin - see http://confluence.jetbrains.com/display/IDEADEV/Run+Configurations
Update: since 2016.x, WebStorm provides a special run configuration - npm - for running/debugging NPM scripts. It can be created manually via Edit configurations... dialog, or auto-added by selecting the script in NPM tool window (can be opened from package.json right-click menu).
See https://www.jetbrains.com/help/webstorm/2017.3/running-npm-scripts.html
WebStorm and IntelliJ 2016 included support for NPM scripts as part of the NodeJS plugin.
Scripts are launched in four ways:
From a tree of scripts in the dedicated NPM Tool Window. The tool window opens when you invoke npm by choosing Show npm Scripts on the context menu of a package.json in the Project tool window or of a package.json opened in the editor.
According to a dedicated run configuration, see Run/Debug Configuration: NPM.
Automatically, as a start-up task.
As a before-launch task, from another run configuration.
For more details check out their documentation.

Resources