Skip to content

Commit aefe778

Browse files
committed
react-hot-loader 3.x need special configuration
1 parent e061473 commit aefe778

File tree

9 files changed

+111
-1
lines changed

9 files changed

+111
-1
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
"@types/node": "^6.0.41",
2222
"babel-cli": "^6.14.0",
2323
"babel-polyfill": "^6.13.0",
24-
"babel-preset-latest": "^6.14.0",
24+
"babel-preset-latest": "^6.16.0",
25+
"babel-preset-react": "^6.16.0",
2526
"babel-register": "^6.14.0"
2627
},
2728
"dependencies": {
2829
"moment": "2.13.0",
30+
"react": "^15.3.2",
31+
"react-dom": "^15.3.2",
32+
"react-hot-loader": "^3.0.0-beta.6",
2933
"request": "^2.74.0",
3034
"webpack": "^1.13.3",
3135
"webpack-dev-server": "^1.16.2",

webpack-dev-server-demo-hot/.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"latest",
4+
"react"
5+
],
6+
"plugins": [
7+
"react-hot-loader/babel"
8+
]
9+
}

webpack-dev-server-demo-hot/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
## CLI MODE:
5+
``` bash
6+
webpack-dev-server --inline --config webpack.config.js --content-base build/
7+
8+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if (module.hot) {
2+
module.hot.accept();
3+
}
4+
5+
6+
7+
require('./test');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var a=document.getElementById('root');
2+
a.innerText='001117778889999'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<div id="root"></div>
9+
<script src="assets/bundle.js"></script>
10+
</body>
11+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Created by joey on 29/10/2016.
3+
*/
4+
5+
'use strict';
6+
7+
const path = require('path');
8+
9+
10+
let webpack = require('webpack');
11+
let WebpackDevServer = require('webpack-dev-server');
12+
13+
14+
var config = require("./webpack.config.js");
15+
config.entry.app.unshift("webpack-dev-server/client?http://localhost:8080/", "webpack/hot/dev-server");
16+
var compiler = webpack(config);
17+
var server = new WebpackDevServer(compiler, {
18+
19+
// server the static html
20+
contentBase:path.join(__dirname,'build'),
21+
22+
// NodeJS API: server js from this path
23+
publicPath: "/assets/",
24+
25+
26+
27+
28+
hot: true
29+
30+
31+
});
32+
server.listen(8080);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "webpack-dev-server-demo-hot",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var path = require("path");
2+
var webpack = require('webpack');
3+
4+
5+
console.log(path.resolve(__dirname, "build"));
6+
module.exports = {
7+
entry: {
8+
app: ["./app/main.js"]
9+
},
10+
output: {
11+
path: path.resolve(__dirname, "build"),
12+
publicPath: "/assets/",
13+
filename: "bundle.js"
14+
},
15+
plugins: [
16+
new webpack.HotModuleReplacementPlugin(),
17+
new webpack.NoErrorsPlugin()
18+
],
19+
module: {
20+
loaders: [{
21+
test: /\.js$/,
22+
loaders: ['babel']
23+
}]
24+
}
25+
};

0 commit comments

Comments
 (0)