Skip to content

Commit

Permalink
baseDir run time options (#115)
Browse files Browse the repository at this point in the history
Yarn support
Nom dependencies upgraded
Documentation updated
  • Loading branch information
andreasonny83 authored and johnpapa committed Feb 25, 2017
1 parent 27c0d5b commit 37ca528
Show file tree
Hide file tree
Showing 6 changed files with 2,723 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"error",
"last"
],
"complexity": "error",
"complexity": ["error", 20],
"computed-property-spacing": "error",
"consistent-return": "error",
"consistent-this": "error",
Expand Down Expand Up @@ -217,4 +217,4 @@
"never"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.idea
coverage/
*.log
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ When creating a SPA there are routes that are only known to the browser. For exa
## Installation and Usage

The recommended installation method is a local NPM install for your project:

```bash
$ npm install lite-server --save-dev
$ yarn add lite-server --dev # or yarn
```

...and add a "script" entry within your project's `package.json` file:
```

```json
# Inside package.json...
"scripts": {
"dev": "lite-server"
},
```

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

```bash
$ npm run dev
```
Expand All @@ -39,6 +43,7 @@ Other options for running locally installed NPM binaries is discussed in this St
### Global Installation

lite-server can be also installed globally, if preferred:

```bash
$ npm install -g lite-server

Expand All @@ -53,11 +58,13 @@ The default behavior serves from the current folder, opens a browser, and applie
lite-server uses [BrowserSync](https://www.browsersync.io/), and allows for configuration overrides via a local `bs-config.json` or `bs-config.js` file in your project.

You can provide custom path to your config file via `-c` or `--config=` run time options:

```bash
lite-server -c configs/my-bs-config.js
```

For example, to change the server port, watched file paths, and base directory for your project, create a `bs-config.json` in your project's folder:

```json
{
"port": 8000,
Expand All @@ -66,7 +73,14 @@ For example, to change the server port, watched file paths, and base directory f
}
```

You can also provide custom path to your base directory `--baseDir=` run time options:

```bash
lite-server --baseDir="dist"
```

A more complicated example with modifications to the server middleware can be done with a `bs-config.js` file, which requires the `module.exports = { ... };` syntax:

```js
module.exports = {
server: {
Expand All @@ -79,6 +93,7 @@ module.exports = {
```

The `bs-config.js` file may also export a function that receives the lite-server Browsersync instance as its only argument. While not required, the return value of this function will be used to extend the default lite-server configuration.

```js
module.exports = function(bs) {

Expand All @@ -98,11 +113,13 @@ module.exports = function(bs) {
```

**NOTE:** Keep in mind that when using middleware overrides the specific middleware module must be installed in your project. For the above example, you'll need to do:

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

...otherwise you'll get an error similar to:

```
Error: Cannot find module 'connect-history-api-fallback'
```
Expand All @@ -112,7 +129,7 @@ Another example: To remove one of the [default middlewares](./lib/config-default
```js
module.exports = {
server: {
middleware: {
middleware: {
0: null // removes default `connect-logger` middleware
}
}
Expand All @@ -125,7 +142,7 @@ A list of the entire set of BrowserSync options can be found in its docs: <http:

When using `lite-server` to run end to end tests, we may not want to log verbosely. We may also want to prevent the browser from opening. These options in the `bs-config.js` will silence all logging from `lite-server`:

```
```js
open: false
logLevel: "silent",
server: {
Expand All @@ -141,13 +158,13 @@ CSS with Angular 2 is embedded thus even though BrowserSync detects the file cha

## Contributing

1. Fork and clone it
1. Install dependencies: `npm install`
1. Create a feature branch: `git checkout -b new-feature`
1. Commit changes: `git commit -am 'Added a feature'`
1. Run static code analysis and unit tests: `npm test`
1. Push to the remote branch: `git push origin new-feature`
1. Create a new [Pull Request](https://github.com/johnpapa/lite-server/pull/new/master)
1. Fork and clone it
1. Install dependencies: `npm install`
1. Create a feature branch: `git checkout -b new-feature`
1. Commit changes: `git commit -am 'Added a feature'`
1. Run static code analysis and unit tests: `npm test`
1. Push to the remote branch: `git push origin new-feature`
1. Create a new [Pull Request](https://github.com/johnpapa/lite-server/pull/new/master)

## License

Expand Down
5 changes: 4 additions & 1 deletion lib/lite-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function start(opts, cb) {
// Load configuration
var argv = require('minimist')(opts.argv.slice(2));
var bsConfigName = argv.c || argv.config || 'bs-config';

// Load optional browser-sync config file from user's project dir
var bsConfigPath = path.resolve(bsConfigName);
var overrides = {};
Expand All @@ -33,6 +34,9 @@ module.exports = function start(opts, cb) {
}
}

// Set optional baseDir
config.server.baseDir = argv.baseDir || config.server.baseDir;

if (typeof overrides === 'function') {
overrides = overrides(browserSync);
}
Expand Down Expand Up @@ -72,4 +76,3 @@ module.exports = function start(opts, cb) {
}

};

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"homepage": "https://github.com/johnpapa/lite-server#readme",
"dependencies": {
"browser-sync": "^2.12.3",
"browser-sync": "^2.18.5",
"connect-history-api-fallback": "^1.2.0",
"connect-logger": "0.0.1",
"lodash": "^4.11.1",
Expand All @@ -36,7 +36,7 @@
"devDependencies": {
"eslint": "^2.8.0",
"istanbul": "^0.4.3",
"mocha": "^2.4.5",
"mocha": "^3.2.0",
"mockery": "^1.6.2",
"sinon": "^1.17.3"
}
Expand Down
Loading

0 comments on commit 37ca528

Please sign in to comment.