Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): add universal-config example (#1810)
- Loading branch information
1 parent
da907f9
commit 0766c32
Showing
5 changed files
with
67 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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"env": { | ||
"browser": true | ||
}, | ||
"rules": { | ||
"no-console": "off" | ||
} | ||
|
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,12 @@ | ||
# General: Webpack Universal Config | ||
|
||
This example demonstrates using a `webpack` config containing a `target: web` config and `target:node` config. | ||
|
||
```console | ||
npm run webpack-dev-server -- --open | ||
``` | ||
|
||
## What Should Happen | ||
|
||
1. The script should open `http://localhost:8080/` in your default browser. | ||
2. You should see the text on the page itself change to read `[client.js, server.js]: 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,25 @@ | ||
'use strict'; | ||
|
||
const target = document.querySelector('#target'); | ||
|
||
if (!window.fetch) { | ||
target.classList.add('fail'); | ||
target.innerHTML = 'fetch is not supported'; | ||
} else { | ||
fetch('/server.js') | ||
.then((res) => { | ||
if (res.status === 404) throw new Error('[server.js]: Not Found'); | ||
return res; | ||
}) | ||
.then((res) => res.text()) | ||
.then((res) => { | ||
if (res.includes("console.log('webpack-dev-server/server');")) { | ||
target.classList.add('pass'); | ||
target.innerHTML = '[client.js, server.js]: Success!'; | ||
} | ||
}) | ||
.catch((e) => { | ||
target.classList.add('fail'); | ||
target.innerHTML = e.message; | ||
}); | ||
} |
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,3 @@ | ||
'use strict'; | ||
|
||
console.log('webpack-dev-server/server'); |
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,24 @@ | ||
'use strict'; | ||
|
||
const { setup } = require('../../util'); | ||
|
||
module.exports = [ | ||
setup({ | ||
mode: 'development', | ||
entry: './client.js', | ||
output: { | ||
filename: 'client.js', | ||
}, | ||
context: __dirname, | ||
}), | ||
{ | ||
mode: 'development', | ||
target: 'node', | ||
entry: './server.js', | ||
output: { | ||
filename: 'server.js', | ||
}, | ||
context: __dirname, | ||
node: false, | ||
}, | ||
]; |