Skip to content

Commit

Permalink
Add more examples, part deux
Browse files Browse the repository at this point in the history
Ref #581
  • Loading branch information
SpaceK33z committed Sep 3, 2016
1 parent 3ddf55d commit 3bfc026
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

Each example showcases a feature. You can use this to learn how to use that feature, but also when making a Pull Request.
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.

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

Expand Down
2 changes: 1 addition & 1 deletion examples/cli-public/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https
# CLI - public

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

Expand Down
2 changes: 1 addition & 1 deletion examples/cli-public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: CLI public</h1>
<h1>Example: CLI - public</h1>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/cli-stdin/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https
# CLI - stdin

```shell
node ../../bin/webpack-dev-server.js --stdin
Expand Down
27 changes: 27 additions & 0 deletions examples/hmr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Hot Module Reloading

```shell
node ../../bin/webpack-dev-server.js --open --hot
```

With Hot Module Reloading we want to apply updates to the page without fully refreshing it.

## What should happen

The script should open `http://localhost:8080/`. In the app you should see "Does it work?"

In your editor, go to `example.js`, and change "Does it work?" to "It works!"

Open the devtools for the app, and you should see:

```
[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
[HMR] Updated modules:
[HMR] - ./example.js
[HMR] - ./hmr.js
[HMR] App is up to date.
```

Also verify that the text actually in the app actually changed to "It works!"
1 change: 1 addition & 0 deletions examples/hmr/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./hmr");
3 changes: 3 additions & 0 deletions examples/hmr/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var myText = document.getElementById("mytext");

myText.textContent = "Does it work? yes";
9 changes: 9 additions & 0 deletions examples/hmr/hmr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("./example");

if (module.hot) {
module.hot.accept(function(err) {
if (err) {
console.error("Cannot apply hot update", err);
}
});
}
8 changes: 8 additions & 0 deletions examples/hmr/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<h1>Example: Hot Module Reloading</h1>
<div id="mytext"></div>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/hmr/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var webpack = require("webpack");

module.exports = {
context: __dirname,
entry: "./app.js",
plugins: [
new webpack.NamedModulesPlugin(),
]
}
2 changes: 1 addition & 1 deletion examples/host-port/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https
# host and port

```shell
node ../../bin/webpack-dev-server.js --open --port 5000 --host 0.0.0.0
Expand Down
18 changes: 18 additions & 0 deletions examples/node-api-middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Node.js API - Middleware

```shell
node server.js
```

Starts a webpack-dev-server setup via the Node API. Open `http://localhost:8080/` to go the app.

## What should happen

In the app you should see "It's working."

In the CLI, you should see this for each refresh in the browser:

```
Using middleware for /
Using middleware for /bundle.js
```
7 changes: 7 additions & 0 deletions examples/node-api-middleware/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
document.write("It's working.");

// This results in a warning:
if(!window) require("./" + window + "parseable.js");

// This results in an error:
// if(!window) require("test");
9 changes: 9 additions & 0 deletions examples/node-api-middleware/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: Node.js API - Middleware</h1>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/node-api-middleware/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var Webpack = require('webpack');
var WebpackDevServer = require("../../lib/Server");
var webpackConfig = require("./webpack.config");

var compiler = Webpack(webpackConfig);
var server = new WebpackDevServer(compiler, {
stats: {
colors: true
},
setup: function(app) {
app.use(function(req, res, next) {
console.log("Using middleware for " + req.url);
next();
});
}
});

server.listen(8080, "127.0.0.1", function() {
console.log("Starting server on http://localhost:8080");
});
9 changes: 9 additions & 0 deletions examples/node-api-middleware/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require('path');

module.exports = {
context: __dirname,
entry: ["./app.js", "../../client/index.js?http://localhost:8080/"],
output: {
filename: "bundle.js"
}
}
15 changes: 15 additions & 0 deletions examples/node-api-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Node.js API - Simple

```shell
node server.js
```

Starts a simple webpack-dev-server setup via the Node API. Open `http://localhost:8080/` to go the app.

## What should happen

In the app you should see "It's working."

In `app.js`, uncomment the code that results in an error and save. This error should be visible in the CLI and devtools.

Then, in `app.js`, uncomment the code that results in a warning. This warning should be visible in the CLI and devtools.
7 changes: 7 additions & 0 deletions examples/node-api-simple/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
document.write("It's working.");

// This results in a warning:
if(!window) require("./" + window + "parseable.js");

// This results in an error:
// if(!window) require("test");
9 changes: 9 additions & 0 deletions examples/node-api-simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: Node.js API - Simple</h1>
</body>
</html>
14 changes: 14 additions & 0 deletions examples/node-api-simple/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var Webpack = require('webpack');
var WebpackDevServer = require("../../lib/Server");
var webpackConfig = require("./webpack.config");

var compiler = Webpack(webpackConfig);
var server = new WebpackDevServer(compiler, {
stats: {
colors: true
}
});

server.listen(8080, "127.0.0.1", function() {
console.log("Starting server on http://localhost:8080");
});
9 changes: 9 additions & 0 deletions examples/node-api-simple/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require('path');

module.exports = {
context: __dirname,
entry: ["./app.js", "../../client/index.js?http://localhost:8080/"],
output: {
filename: "bundle.js"
}
}
2 changes: 1 addition & 1 deletion examples/proxy-advanced/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Proxy: simple
# Proxy: advanced

```shell
node ../../bin/webpack-dev-server.js --open
Expand Down

0 comments on commit 3bfc026

Please sign in to comment.