File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Magic HTML
2
+
3
+ Enables/Disables magic HTML routes (enabled by default).
4
+
5
+ ## true
6
+
7
+ Setting it to ` true ` will enable magic HTML routes ( routes corresponding to your webpack output, in this example ` /main ` for ` main.js ` ):
8
+
9
+ ** webpack.config.js**
10
+
11
+ ``` js
12
+ module .exports = {
13
+ // ...
14
+ devServer: {
15
+ magicHtml: true ,
16
+ },
17
+ };
18
+ ```
19
+
20
+ Usage via CLI:
21
+
22
+ ``` console
23
+ npx webpack serve --magic-html --open
24
+ ```
25
+
26
+ ### What Should Happen
27
+
28
+ 1 . The script should open ` http://localhost:8080/ ` in your default browser.
29
+ 2 . Go to ` http://localhost:8080/main ` , you should see the text on the page itself change to read ` You are viewing the magic HTML route! ` .
30
+
31
+ ## false
32
+
33
+ Setting it to ` false ` will disable magic HTML route (` /main ` ):
34
+
35
+ ** webpack.config.js**
36
+
37
+ ``` js
38
+ module .exports = {
39
+ // ...
40
+ devServer: {
41
+ magicHtml: false ,
42
+ },
43
+ };
44
+ ```
45
+
46
+ Usage via CLI:
47
+
48
+ ``` console
49
+ npx webpack serve --no-magic-html --open
50
+ ```
51
+
52
+ ### What Should Happen
53
+
54
+ 1 . The script should open ` http://localhost:8080/ ` in your default browser.
55
+ 2 . Go to ` http://localhost:8080/main ` , you should see the text on the page itself change to read ` Cannot GET /main ` as it is not accessible.
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ if ( window . location . href . endsWith ( "main" ) ) {
4
+ document . querySelector ( "body" ) . innerHTML =
5
+ "<div>You are viewing the magic HTML route!</div>" ;
6
+ } else {
7
+ const target = document . querySelector ( "#target" ) ;
8
+
9
+ target . classList . add ( "pass" ) ;
10
+ target . innerHTML = "Success!" ;
11
+ }
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ // our setup function adds behind-the-scenes bits to the config that all of our
4
+ // examples need
5
+ const { setup } = require ( "../util" ) ;
6
+
7
+ module . exports = setup ( {
8
+ context : __dirname ,
9
+ entry : "./app.js" ,
10
+ devServer : {
11
+ magicHtml : true ,
12
+ } ,
13
+ } ) ;
You can’t perform that action at this time.
0 commit comments