Skip to content

Commit

Permalink
Start with examples
Browse files Browse the repository at this point in the history
Ref #581
  • Loading branch information
SpaceK33z committed Sep 3, 2016
1 parent c706a9b commit 6d064d9
Show file tree
Hide file tree
Showing 36 changed files with 223 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
root = true

[*.js]
[*.{js,html,less}]
indent_style=tab
trim_trailing_whitespace=true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/

The client scripts are built with `npm run-script prepublish`.

Run the relevant [examples](https://github.com/webpack/webpack-dev-server/tree/master/examples) to see if all functionality still works.

When making a PR, keep these goals in mind:

- The communication library (Sock.js) should not be exposed to the user.
Expand Down
66 changes: 0 additions & 66 deletions example/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions example/alternative.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Examples

Each example showcases a feature. You can use this to learn how to use that feature, but also when making a Pull Request.

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

- The code that is necessary
- Instructions on how to run
- A description of what should happen
11 changes: 11 additions & 0 deletions examples/https/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https

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

A fake certificate is used to enable https.

## What should happen

The script should open `https://localhost:8080/`. Your browser will probably give you a warning about using an invalid certificate. After ignoring this warning, you should see "It's working."
1 change: 1 addition & 0 deletions examples/https/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.write("It's working.");
9 changes: 9 additions & 0 deletions examples/https/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: https</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/https/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
15 changes: 15 additions & 0 deletions examples/modus-iframe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Modus: iframe

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

The app is started in an iframe. The page contains the client script to connect to webpack-dev-server.

## What should happen

It should open `http://localhost:8080/webpack-dev-server/`. In the bar at the top, the text should say `App ready.`

In `app.js`, uncomment the code that results in an error and save. The bar at the top should display `Errors while compiling. App updated with errors. No reload!` with a stack trace underneath it.

Then, in `app.js`, uncomment the code that results in a warning. The bar at the top should display `Warnings while compiling.`.
7 changes: 7 additions & 0 deletions examples/modus-iframe/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/modus-iframe/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: iframe</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/modus-iframe/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
23 changes: 23 additions & 0 deletions examples/modus-inline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Modus: inline

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

This opens the app in `inline` modus (which is the default).

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

This also opens the app in `inline` modus, but with a custom config.

## What should happen

The script should open `http://localhost:8080/`. It should display "It's working" with a dotted background.

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.

Also try to change something in `style.less`. The browser should refresh, and the change should be visible in the app.
File renamed without changes.
1 change: 1 addition & 0 deletions example/index.html → examples/modus-inline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>Example: inline</h1>
<br>
<img src="/svg.svg" style="width: 200px;">
</body>
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions examples/modus-lazy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Modus: lazy

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

With the `lazy` modus, webpack-dev-server does *not* watch the files, automatically recompiles them and refresh the browser. Instead, it only compiles after you manually refresh the page.

## What should happen

The script should open `http://localhost:8080/`. You should see "It's working."

Change something in `app.js` and save. Check that in the CLI, nothing changed. Also check that in the browser, the old content is still displayed.

Now refresh the app. The CLI should now compile. In the app you should now see the new content.
7 changes: 7 additions & 0 deletions examples/modus-lazy/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/modus-lazy/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: lazy</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/modus-lazy/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
13 changes: 13 additions & 0 deletions examples/modus-manual-script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Modus: manual script

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

The webpack-dev-server client is added as script tag to the html page.

## What should happen

Try to update app.js by uncommenting some lines. The browser should reflect your changes.

If there is a compilation error or warning, this should be displayed in the CLI and devtools.
7 changes: 7 additions & 0 deletions examples/modus-manual-script/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");
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<script src="bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<br>
<img src="svg.svg" style="width: 200px;">
<h1>Example: manual script</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/modus-manual-script/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
context: __dirname,
entry: "./app.js",
}
13 changes: 13 additions & 0 deletions examples/webpack-config-array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Webpack config array

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

This opens the app with two webpack configs.

## What should happen

The script should open `http://localhost:8080/`. It should display "It's working" with a dotted background.

Browsing to `http://localhost:8080/bundle2.js` should show a minified JS bundle.
9 changes: 9 additions & 0 deletions examples/webpack-config-array/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("./style.less");

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/webpack-config-array/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: webpack config array</h1>
</body>
</html>
Binary file added examples/webpack-config-array/pixels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/webpack-config-array/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: url(pixels.png);
}
33 changes: 33 additions & 0 deletions examples/webpack-config-array/svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.

0 comments on commit 6d064d9

Please sign in to comment.