Skip to content

Commit b6d22d7

Browse files
committed
Merge pull request #9 from christianalfoni/master
update
2 parents 3adc711 + efb7b5b commit b6d22d7

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

content/Automatic-browser-refresh.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
When **webpack-dev-server** is running it will watch your files for changes. When that happens it rebundles your project and notifies browsers listening to refresh. To trigger this behavior you need to change your *index.html* file in the `build/` folder.
22

3-
*build/index.html*
3+
**build/index.html**
44

55
```html
66
<!DOCTYPE html>
@@ -9,21 +9,24 @@ When **webpack-dev-server** is running it will watch your files for changes. Whe
99
<meta charset="UTF-8"/>
1010
</head>
1111
<body>
12-
<script src="http://localhost:8080/webpack-dev-server.js"></script>
1312
<script src="bundle.js"></script>
1413
</body>
1514
</html>
1615
```
1716

1817
We added a script that refreshes the application when a change occurs. You will also need to add an entry point to your configuration:
1918

20-
*webpack.config.js*
19+
**webpack.config.js**
2120

2221
```javascript
2322
var path = require('path');
2423

2524
module.exports = {
26-
entry: ['webpack/hot/dev-server', path.resolve(__dirname, 'app/main.js')],
25+
entry: [
26+
'webpack/hot/dev-server',
27+
'webpack-dev-server/client?http://localhost:8080',
28+
path.resolve(__dirname, 'app/main.js')
29+
],
2730
output: {
2831
path: path.resolve(__dirname, 'build'),
2932
filename: 'bundle.js',
@@ -34,4 +37,7 @@ module.exports = {
3437
Thats it! Now your application will automatically refresh on file changes.
3538

3639
## Default environment
37-
In the example above we created our own *index.html* file to give more freedom and control. It is also possible to run the application from **http://localhost:8080/webpack-dev-server/bundle**. This will fire up a default *index.html* file that you do not control. It also fires this file up in an iFrame allowing for a status bar to indicate the status of the rebundling process.
40+
41+
In the example above we created our own *index.html* file to give more freedom and control. It is also possible to run the application from **http://localhost:8080/webpack-dev-server/bundle**. This will fire up a default *index.html* file that you do not control. It also fires this file up in an iFrame allowing for a status bar to indicate the status of the rebundling process.
42+
43+
> I discuss an alternative, `inline` based approach at the [Developing with Webpack](http://survivejs.com/webpack_react/developing_with_webpack/) chapter of *SurviveJS - Webpack and React*.

content/Optimizing-rebundling.md

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
You might notice after requiring React JS into your project that the time it takes from a save to a finished rebundle of your application takes more time. In development you ideally want from 200-800 ms rebundle speed, depending on what part of the application you are working on.
22

3+
> IMPORTANT! This setup a minified, production version of React. As a result you will lose `propTypes` based type validation!
4+
35
## Running minified file in development
6+
47
Instead of making Webpack go through React JS and all its dependencies, you can override the behavior in development.
58

6-
*webpack.config.js*
9+
**webpack.config.js**
10+
711
```javascript
812
var path = require('path');
913
var node_modules = path.resolve(__dirname, 'node_modules');
@@ -12,25 +16,26 @@ var pathToReact = path.resolve(node_modules, 'react/dist/react.min.js');
1216
config = {
1317
entry: ['webpack/hot/dev-server', path.resolve(__dirname, 'app/main.js')],
1418
resolve: {
15-
alias: {
16-
'react': pathToReact
17-
}
18-
},
19+
alias: {
20+
'react': pathToReact
21+
}
22+
},
1923
output: {
2024
path: path.resolve(__dirname, 'build'),
2125
filename: 'bundle.js',
2226
},
2327
module: {
24-
loaders: [{
25-
test: /\.jsx?$/,
26-
loader: 'babel'
27-
}],
28-
noParse: [pathToReact]
29-
}
28+
loaders: [{
29+
test: /\.jsx?$/,
30+
loader: 'babel'
31+
}],
32+
noParse: [pathToReact]
33+
}
3034
};
3135

3236
module.exports = config;
3337
```
38+
3439
We do two things in this configuration:
3540

3641
1. Whenever "react" is required in the code it will fetch the minified React JS file instead of going to *node_modules*

0 commit comments

Comments
 (0)