Created
June 22, 2016 17:19
-
-
Save thetamind/2240c44c56526cff7373843ca5637ce5 to your computer and use it in GitHub Desktop.
webpack-dev-hot-middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From af112ef6f3f843df98ca68bfd54f63d07d4768e9 Mon Sep 17 00:00:00 2001 | |
From: Matthew Boehlig <[email protected]> | |
Date: Mon, 6 Jun 2016 13:05:18 -0500 | |
Subject: [PATCH 1/1] Try dev-hot-middleware | |
Adopt example from https://github.com/glenjamin/byte-board | |
--- | |
package.json | 4 ++++ | |
server.js | 28 ++++++++++++++++++++++++++++ | |
webpack.config.js | 2 ++ | |
3 files changed, 34 insertions(+) | |
create mode 100644 server.js | |
diff --git a/package.json b/package.json | |
index 9f82079..7058fb5 100755 | |
--- a/package.json | |
+++ b/package.json | |
@@ -10,6 +10,7 @@ | |
}, | |
"scripts": { | |
"start": "webpack-dev-server --hot --inline --content-base src/", | |
+ "dev": "node server.js", | |
"watch": "webpack --watch" | |
}, | |
@@ -20,6 +21,7 @@ | |
"elm": "0.17.0", | |
"elm-hot-loader": "0.3.2", | |
"elm-webpack-loader": "^3.0.3", | |
+ "express": "^4.13.4", | |
"extract-text-webpack-plugin": "1.0.1", | |
"file-loader": "0.8.5", | |
"html-webpack-plugin": "2.17.0", | |
@@ -30,7 +32,9 @@ | |
"style-loader": "0.13.1", | |
"url-loader": "^0.5.7", | |
"webpack": "^1.13.1", | |
+ "webpack-dev-middleware": "^1.6.1", | |
"webpack-dev-server": "1.14.1", | |
+ "webpack-hot-middleware": "^2.10.0", | |
"webpack-merge": "^0.13.0" | |
} | |
} | |
diff --git a/server.js b/server.js | |
new file mode 100644 | |
index 0000000..91c072a | |
--- /dev/null | |
+++ b/server.js | |
@@ -0,0 +1,28 @@ | |
+var http = require('http'); | |
+var path = require('path'); | |
+ | |
+var express = require('express'); | |
+var webpack = require('webpack'); | |
+ | |
+var webpackConfig = require('./webpack.config'); | |
+var compiler = webpack(webpackConfig); | |
+ | |
+var app = express(); | |
+ | |
+app.use(require('webpack-dev-middleware')(compiler, { | |
+ noInfo: true, publicPath: webpackConfig.output.publicPath | |
+})); | |
+app.use(require('webpack-hot-middleware')(compiler)); | |
+app.use(express.static(webpackConfig.output.assetPath)); | |
+ | |
+app.get('/', function(req, res) { | |
+ res.sendFile(path.join(__dirname, 'public/index.html')); | |
+}); | |
+ | |
+var server = http.createServer(app); | |
+ | |
+var port = process.env.PORT || '7654' | |
+ | |
+server.listen(port, function() { | |
+ console.log("Listening on http://localhost:" + port); | |
+}); | |
diff --git a/webpack.config.js b/webpack.config.js | |
index f6eda3b..0f2ee86 100755 | |
--- a/webpack.config.js | |
+++ b/webpack.config.js | |
@@ -15,6 +15,8 @@ var commonConfig = { | |
output: { | |
path: path.resolve( __dirname, 'dist/' ), | |
+ publicPath: '/', | |
+ assetPath: 'src/', | |
filename: '[hash].js', | |
}, | |
-- | |
2.9.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment