smooth-server

Little node server based on lite-server and browsersync


Keywords
smooth-server, server, lite-server, tiny, browsersync, node, nodejs
License
ISC
Install
npm install smooth-server@1.3.1

Documentation

smooth-server

A simple local development HTTP server optimized for productivity.

Installation

Local Installation

$ npm install smooth-server --save-dev
$ yarn add smooth-server --dev

After installing, add following "script" entry within your project's package.json file:

{
  "scripts": {
    "dev": "smooth-server"
  },
}

With the above script entry, you can then start smooth-server via:

$ npm run dev

You can also specify a configuration file:

{
  "scripts": {
    "dev": "smooth-server --config path/config.json"
  },
}

If a config file is not found the default port will be 3333 and the listened files will be ["./**/*.{html,htm,css,js}"].

Global Installation

$ npm install -g smooth-server

You can run it directly from the command line:

$ smooth-server
$ smooth-server --config path/smooth-server.config.json

Custom Configuration

The default behavior serves from the current directory, opens a browser, and applies a HTML5 route fallback to ./index.html.

smooth-server uses BrowserSync, and allows for configuration overrides via a local bs-config.json or bs-config.js file in your project. If these files do not exist, it will use the default configuration.

You can provide custom path to your config file via -c or --config= command line options:

smooth-server -c configs/my-bs-config.js

Configuring via bs-config.json

{
  "port": 8081,
  "files": ["./www/**/*.{html,htm,css,js}"],
  "server": { "baseDir": "./src" }
}

Configuring via bs-config.js

This approach is more flexible and allows using JavaScript instead of a static JSON.

module.exports = {
  server: {
    middleware: {
      // overrides the second middleware default with new settings
      1: require('connect-history-api-fallback')({index: '/index.html', verbose: true})
    }
  }
};

Full list of BrowserSync options can be found in its docs: http://www.browsersync.io/docs/options/

Note: When using middleware overrides the specific middleware module must be installed in your project. For the above example, connect-history-api-fallback package needs to be installed in your project:

$ npm install connect-history-api-fallback --save-dev

Or else, you will get an error:

Error: Cannot find module 'connect-history-api-fallback'

TIP: To remove one of the default middlewares such as connect-logger, set its array index to null:

module.exports = {
  server: {
    middleware: {
      0: null     // removes default `connect-logger` middleware
    }
  }
};