Skip to content

Commit 0766c32

Browse files
hiroppyevilebottnawi
authored andcommitted
chore(examples): add universal-config example (#1810)
1 parent da907f9 commit 0766c32

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

examples/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"env": {
3+
"browser": true
4+
},
25
"rules": {
36
"no-console": "off"
47
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# General: Webpack Universal Config
2+
3+
This example demonstrates using a `webpack` config containing a `target: web` config and `target:node` config.
4+
5+
```console
6+
npm run webpack-dev-server -- --open
7+
```
8+
9+
## What Should Happen
10+
11+
1. The script should open `http://localhost:8080/` in your default browser.
12+
2. You should see the text on the page itself change to read `[client.js, server.js]: Success!`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const target = document.querySelector('#target');
4+
5+
if (!window.fetch) {
6+
target.classList.add('fail');
7+
target.innerHTML = 'fetch is not supported';
8+
} else {
9+
fetch('/server.js')
10+
.then((res) => {
11+
if (res.status === 404) throw new Error('[server.js]: Not Found');
12+
return res;
13+
})
14+
.then((res) => res.text())
15+
.then((res) => {
16+
if (res.includes("console.log('webpack-dev-server/server');")) {
17+
target.classList.add('pass');
18+
target.innerHTML = '[client.js, server.js]: Success!';
19+
}
20+
})
21+
.catch((e) => {
22+
target.classList.add('fail');
23+
target.innerHTML = e.message;
24+
});
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log('webpack-dev-server/server');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const { setup } = require('../../util');
4+
5+
module.exports = [
6+
setup({
7+
mode: 'development',
8+
entry: './client.js',
9+
output: {
10+
filename: 'client.js',
11+
},
12+
context: __dirname,
13+
}),
14+
{
15+
mode: 'development',
16+
target: 'node',
17+
entry: './server.js',
18+
output: {
19+
filename: 'server.js',
20+
},
21+
context: __dirname,
22+
node: false,
23+
},
24+
];

0 commit comments

Comments
 (0)