https://github.com/unfold/dev-server
Webpack development server
https://github.com/unfold/dev-server
Last synced: 5 months ago
JSON representation
Webpack development server
- Host: GitHub
- URL: https://github.com/unfold/dev-server
- Owner: unfold
- Created: 2015-04-14T09:01:32.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-13T14:20:08.000Z (almost 10 years ago)
- Last Synced: 2025-09-23T01:21:17.933Z (10 months ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 12
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Webpack development server
Development server for webpack with hot module reloading, simplified console outpout and [connect middleware](https://github.com/senchalabs/connect/wiki) support.
## Installation
`$ npm install unfold/dev-server`
## Usage
it can be run globally as `$ dev-server` or as a module `require('dev-server')()` and defaults to webpack.config.js in current directory and serves from http://localhost:3000.
## Example
If your application depends on a server, you can pass it on to the dev-server as a middleware to serve requests for content and API calls.
**app.js**
``` javascript
var express = require('express')
var app = express()
var api = require('./api')
app.use(express.static('./build'))
app.use('/api', api);
app.use(function(req, res) {
res.sendFile('./src/index.html')
})
if (!module.parent) {
app.listen(process.env.PORT || 80)
}
module.exports = app
```
**lib/development-server.js**
``` javascript
var path = require('path')
var devServer = require('dev-server')
devServer({
port: 5000,
hostname: 'myproject.dev',
config: path.resolve(__dirname, '../webpack.config.js'),
middleware: path.resolve(__dirname, '../app.js')
})
```
Start it with `$ node lib/development-server` or add it to your your package.json
``` json
…
scripts: {
"start": "node app.js",
"serve": "node lib/development-server.js"
}
…
```
and run `$ npm run serve`
## Options
Options can be accessed with `$ dev-server -h`
```
-v --version output the version number
-p, --port serve from port
-H, --hostname serve from hostname
-c, --config your webpack config
-m, --middleware optional connect middleware
-e, --env [path] import environment. defaults to .env
-f, --history-fallback fallback to / url is a directory
--log-browser-connections log all browsers who connect to server
```