File tree Expand file tree Collapse file tree 5 files changed +35
-4
lines changed Expand file tree Collapse file tree 5 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 11import webpack from 'webpack' ;
22import webpackConfig from '../webpack.config' ;
33import webpackDevMiddleware from 'webpack-dev-middleware' ;
4+ import webpackHotMiddleware from 'webpack-hot-middleware' ;
45import express from 'express' ;
56
67const app = express ( ) ;
@@ -15,6 +16,10 @@ app.use(webpackDevMiddleware(compiler, {
1516 publicPath : webpackConfig . output . publicPath
1617} ) ) ;
1718
19+ app . use ( webpackHotMiddleware ( compiler , {
20+ log : console . log
21+ } ) ) ;
22+
1823app . use ( express . static ( './public' ) ) ;
1924
2025app . get ( '/hello' , function ( req , res ) {
Original file line number Diff line number Diff line change 1717 "css-loader" : " ^0.23.1" ,
1818 "style-loader" : " ^0.13.1" ,
1919 "webpack" : " ^1.13.1" ,
20- "webpack-dev-middleware" : " ^1.6.1"
20+ "webpack-dev-middleware" : " ^1.6.1" ,
21+ "webpack-hot-middleware" : " ^2.12.2"
2122 },
2223 "dependencies" : {
2324 "babel-preset-es2015" : " ^6.13.2" ,
Original file line number Diff line number Diff line change 1- document . write ( 'it works' ) ;
1+ // Notice!!
2+ // we can't use `document.write(...)` here
3+ // which is not allow and produce error:
4+ // It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
5+ const content = document . getElementById ( 'content' )
6+ content . innerHTML = 'it works' ;
7+
8+ // Notice!!!
9+ // Following is required to make reloading happen
10+ if ( module . hot ) {
11+ module . hot . accept ( ) ;
12+ }
Original file line number Diff line number Diff line change 55 < title > Es6 Project Demo</ title >
66</ head >
77< body >
8+ < div id ='content '> </ div >
89 < script src ="/assets/bundle.js "> </ script >
910</ body >
1011</ html >
Original file line number Diff line number Diff line change 1+ const webpack = require ( 'webpack' ) ;
2+
13module . exports = {
2- entry : './public/entry.js' ,
4+ entry : [
5+ './public/entry.js' ,
6+ 'webpack-hot-middleware/client'
7+ ] ,
38 output : {
49 path : __dirname ,
510 publicPath : '/assets/' ,
@@ -14,5 +19,13 @@ module.exports = {
1419 presets : [ 'es2015' ]
1520 }
1621 } ]
17- }
22+ } ,
23+ plugins : [
24+ // Webpack 1.0
25+ new webpack . optimize . OccurenceOrderPlugin ( ) ,
26+ // Webpack 2.0 fixed this mispelling
27+ // new webpack.optimize.OccurrenceOrderPlugin(),
28+ new webpack . HotModuleReplacementPlugin ( ) ,
29+ new webpack . NoErrorsPlugin ( )
30+ ]
1831}
You can’t perform that action at this time.
0 commit comments