21

I'm using browser sync that I installed with NPM to watch my projects as I work on them. Is there a way to get it to watch the root folder and the css folder at once?

Caleb Prenger
  • 309
  • 1
  • 4
  • 10

2 Answers2

27

A bit late, but still, since I needed it I'll post it here for future reference :

Either start browser-sync init and add something like this to the bs-config.js file :

files: ["app/css/style.css", "app/js/*.js"]

or start browser-sync with following option :

browser-sync start --server --files="**/*"

This will load current directory AND every other subdirectory.

source : https://www.browsersync.io/docs/options/

Antoine
  • 371
  • 4
  • 7
  • 1
    if we want to use port 3001 then we need to use "--port 3001" otherwise it isn't necessary in case of browser-sync start --server --port 3001 --files="**/*" – Tanveer Hossain Jony Oct 19 '16 at 18:26
  • 1
    where is this `--files="**/*"` mentioned in the documentation ? – Ankur Agarwal Jun 09 '17 at 00:53
  • 2
    @abc In the doc, you will only find the `--files` flag. The `**/*` part comes from your shell, and it does the same as `*` with the slight difference that it also matches every subdirectory at any level. There might be some differences depending on which shell you use, here is a nice description : https://unix.stackexchange.com/questions/62660/the-result-of-ls-ls-and-ls – Antoine Jun 12 '17 at 12:57
  • @TanveerHossainJony Just saw your comment, updated the initial answer. – Antoine Jun 12 '17 at 12:58
13

To watch multiple files, list the different directories after the --files options, e.g. --files 'directory1' 'directory2/sub'.

An entire npm script command can look like this: browser-sync start --proxy 'localhost:3000' --files 'public' 'src' 'views'

criticalJ
  • 131
  • 1
  • 4