A simple local development HTTP server optimized for productivity.
$ npm install smooth-server --save-dev
$ yarn add smooth-server --devAfter 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 devYou 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}"].
$ npm install -g smooth-serverYou can run it directly from the command line:
$ smooth-server
$ smooth-server --config path/smooth-server.config.jsonThe 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{
"port": 8081,
"files": ["./www/**/*.{html,htm,css,js}"],
"server": { "baseDir": "./src" }
}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-fallbackpackage needs to be installed in your project:
$ npm install connect-history-api-fallback --save-devOr 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 tonull:
module.exports = {
server: {
middleware: {
0: null // removes default `connect-logger` middleware
}
}
};