File tree Expand file tree Collapse file tree 5 files changed +67
-0
lines changed Expand file tree Collapse file tree 5 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1
1
{
2
+ "env": {
3
+ "browser": true
4
+ },
2
5
"rules": {
3
6
"no-console": "off"
4
7
}
Original file line number Diff line number Diff line change
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! ` .
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ console . log ( 'webpack-dev-server/server' ) ;
Original file line number Diff line number Diff line change
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
+ ] ;
You can’t perform that action at this time.
0 commit comments