-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# API: start | ||
|
||
While it's recommended to run `webpack-dev-server` via the CLI, you may also | ||
choose to start a server via the API. | ||
|
||
This example demonstrates using `start` method. It instructs `webpack-dev-server` instance to stop watching for file changes. | ||
|
||
```js | ||
const Webpack = require("webpack"); | ||
const WebpackDevServer = require("webpack-dev-server"); | ||
const webpackConfig = require("./webpack.config"); | ||
|
||
const compiler = Webpack(webpackConfig); | ||
const devServerOptions = { ...webpackConfig.devServer }; | ||
const server = new WebpackDevServer(devServerOptions, compiler); | ||
|
||
const runServer = async () => { | ||
console.log("Starting server..."); | ||
await server.start(); | ||
}; | ||
|
||
runServer(); | ||
``` | ||
|
||
Use the following command to run this example: | ||
|
||
```console | ||
node server.js | ||
``` | ||
|
||
## What Should Happen | ||
|
||
1. Open `http://localhost:8080/` in your preferred browser. | ||
2. You should see the text on the page itself change to read `Success!`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
const target = document.querySelector("#target"); | ||
|
||
target.classList.add("pass"); | ||
target.innerHTML = "Success!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
|
||
const Webpack = require("webpack"); | ||
const WebpackDevServer = require("../../../lib/Server"); | ||
const webpackConfig = require("./webpack.config"); | ||
|
||
const compiler = Webpack(webpackConfig); | ||
const devServerOptions = { ...webpackConfig.devServer, open: true }; | ||
const server = new WebpackDevServer(devServerOptions, compiler); | ||
|
||
const runServer = async () => { | ||
console.log("Starting server..."); | ||
await server.start(); | ||
}; | ||
|
||
runServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
|
||
// our setup function adds behind-the-scenes bits to the config that all of our | ||
// examples need | ||
const { setup } = require("../../util"); | ||
|
||
module.exports = setup({ | ||
context: __dirname, | ||
entry: "./app.js", | ||
output: { | ||
filename: "bundle.js", | ||
}, | ||
stats: { | ||
colors: true, | ||
}, | ||
}); |