Permalink
Browse files

Dev Server

  • Loading branch information...
cazala committed Aug 8, 2016
1 parent fe166a5 commit b35ee38c160f72f3598832400f77d918ce09a40b
Showing with 54 additions and 7 deletions.
  1. +36 −0 dev-server.js
  2. +8 −1 package.json
  3. +0 −4 src/index.js
  4. +10 −2 webpack.config.js
@@ -0,0 +1,36 @@
var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config.js')
var Express = require('express')

var app = new Express()
var port = process.env.PORT || 9999
var compiler = webpack(config)
var dev = webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath })
var hot = webpackHotMiddleware(compiler)

app.use(dev)
app.use(hot)

app.get('*', function (req, res) {
res.send(`
<html>
<head>
<title>Webpack Development Server</title>
</head>
<body>
<div id="root">Hello World</div>
</body>
<script src="/bundle.js" async defer></script>
</html>
`)
})

app.listen(port, (error) => {
if (error) {
console.error(error)
return
}
console.info('Open up http://localhost:%s/ in your browser.', port)
})
@@ -6,6 +6,7 @@
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "node dist/bundle.js",
"dev-server": "node dev-server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
@@ -18,6 +19,7 @@
"devDependencies": {
"autoprefixer": "^6.4.0",
"babel-core": "^6.13.2",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-plugin-jsx-display-if": "^3.0.0",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
@@ -44,6 +46,11 @@
"postcss-simple-vars": "^3.0.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.1"
"webpack": "^1.13.1",
"webpack-dev-middleware": "^1.6.1",
"webpack-hot-middleware": "^2.12.2"
},
"dependencies": {
"express": "^4.14.0"
}
}

This file was deleted.

Oops, something went wrong.
@@ -2,12 +2,20 @@ var webpack = require('webpack')
var path = require('path')
module.exports = {
context: __dirname,
entry: './src/index.js',
devtool: 'cheap-module-eval-source-map',
entry: [
'webpack-hot-middleware/client',
'./src/index.js'
],
output: {
path: path.resolve('dist'),
filename: 'bundle.js',
publicPath: '/'
},
plugins: [ new webpack.NoErrorsPlugin() ],
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js', '.json', '.css', 'scss'],
modulesDirectories: ['.', 'src', 'node_modules']

0 comments on commit b35ee38

Please sign in to comment.