Skip to content

Commit 3bfc026

Browse files
committed
Add more examples, part deux
Ref #581
1 parent 3ddf55d commit 3bfc026

File tree

22 files changed

+180
-6
lines changed

22 files changed

+180
-6
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Examples
22

3-
Each example showcases a feature. You can use this to learn how to use that feature, but also when making a Pull Request.
3+
Each example showcases a feature. You can use this to learn how to use that feature, but also use it to test if something still works when making a Pull Request.
44

55
An example should be as minimal as possible, and consists of:
66

examples/cli-public/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https
1+
# CLI - public
22

33
NOTE: replace `<insert local ip>` with your local ip.
44

examples/cli-public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
55
</head>
66
<body>
7-
<h1>Example: CLI public</h1>
7+
<h1>Example: CLI - public</h1>
88
</body>
99
</html>

examples/cli-stdin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https
1+
# CLI - stdin
22

33
```shell
44
node ../../bin/webpack-dev-server.js --stdin

examples/hmr/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Hot Module Reloading
2+
3+
```shell
4+
node ../../bin/webpack-dev-server.js --open --hot
5+
```
6+
7+
With Hot Module Reloading we want to apply updates to the page without fully refreshing it.
8+
9+
## What should happen
10+
11+
The script should open `http://localhost:8080/`. In the app you should see "Does it work?"
12+
13+
In your editor, go to `example.js`, and change "Does it work?" to "It works!"
14+
15+
Open the devtools for the app, and you should see:
16+
17+
```
18+
[WDS] App updated. Recompiling...
19+
[WDS] App hot update...
20+
[HMR] Checking for updates on the server...
21+
[HMR] Updated modules:
22+
[HMR] - ./example.js
23+
[HMR] - ./hmr.js
24+
[HMR] App is up to date.
25+
```
26+
27+
Also verify that the text actually in the app actually changed to "It works!"

examples/hmr/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./hmr");

examples/hmr/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var myText = document.getElementById("mytext");
2+
3+
myText.textContent = "Does it work? yes";

examples/hmr/hmr.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("./example");
2+
3+
if (module.hot) {
4+
module.hot.accept(function(err) {
5+
if (err) {
6+
console.error("Cannot apply hot update", err);
7+
}
8+
});
9+
}

examples/hmr/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>Example: Hot Module Reloading</h1>
5+
<div id="mytext"></div>
6+
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
7+
</body>
8+
</html>

examples/hmr/webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var webpack = require("webpack");
2+
3+
module.exports = {
4+
context: __dirname,
5+
entry: "./app.js",
6+
plugins: [
7+
new webpack.NamedModulesPlugin(),
8+
]
9+
}

0 commit comments

Comments
 (0)