@@ -10,10 +10,10 @@ Allow creating virtual modules of any type, such as `.ts`, `.json`, `.css`, etc.
10
10
<Badge text = " 5.100.0+" />
11
11
12
12
``` javascript
13
- const webpack = require (" webpack)
13
+ const webpack = require (' webpack' );
14
14
15
15
new webpack.experiments.schemes.VirtualUrlPlugin ({
16
- myModule: `export const msg = " from virtual module " `
16
+ myModule: ` export const msg = "from virtual module"` ,
17
17
});
18
18
```
19
19
@@ -30,7 +30,7 @@ console.log(msg);
30
30
Create a virtual module that generates build information
31
31
32
32
``` javascript
33
- const webpack = require(" webpack)
33
+ const webpack = require (" webpack" )
34
34
35
35
new webpack.experiments.schemes.VirtualUrlPlugin ({
36
36
buildInfo: {
@@ -53,11 +53,14 @@ console.log('App version: ', buildTime);
53
53
Use custom schema
54
54
55
55
``` javascript
56
- const webpack = require (" webpack)
56
+ const webpack = require (' webpack' );
57
57
58
- new webpack.experiments.schemes.VirtualUrlPlugin({
59
- myModule: `export const msg = " from virtual module " `
60
- }, " v" );
58
+ new webpack.experiments.schemes.VirtualUrlPlugin (
59
+ {
60
+ myModule: ` export const msg = "from virtual module"` ,
61
+ },
62
+ ' v'
63
+ );
61
64
```
62
65
63
66
** src/app.js**
@@ -73,15 +76,15 @@ console.log(msg);
73
76
Create multiple virtual modules of different types
74
77
75
78
``` javascript
76
- const webpack = require(" webpack)
79
+ const webpack = require (' webpack' );
77
80
78
81
new webpack.experiments.schemes.VirtualUrlPlugin ({
79
82
myCssModule: {
80
- type: " .css" ,
81
- source: " body{background-color: powderblue;}" ,
83
+ type: ' .css' ,
84
+ source: ' body{background-color: powderblue;}' ,
82
85
},
83
86
myJsonModule: {
84
- type: " .json" ,
87
+ type: ' .json' ,
85
88
source: ` {"name": "virtual-url-plugin"}` ,
86
89
},
87
90
});
@@ -97,24 +100,24 @@ import 'virtual:myCssModule';
97
100
Virtualize the routing file
98
101
99
102
``` javascript
100
- const webpack = require (" webpack" )
101
- const path = require (" path)
102
- const watchDir = path.join(__dirname, " ./ src/ routes" )
103
+ const webpack = require (' webpack' );
104
+ const path = require (' path' );
105
+ const watchDir = path .join (__dirname , ' ./src/routes' );
103
106
104
107
new webpack.experiments.schemes.VirtualUrlPlugin ({
105
108
routes: {
106
109
source (loaderContext ) {
107
110
// Use addContextDependency to monitor the addition or removal of subdirectories in watchDir to trigger the rebuilding of virtual modules.
108
- loaderContext.addContextDependency(watchDir)
111
+ loaderContext .addContextDependency (watchDir);
109
112
110
- const files = fs.readdirSync(watchDir)
113
+ const files = fs .readdirSync (watchDir);
111
114
return `
112
115
export const routes = {
113
- ${files.map(key => `${key.split(" . " )[0]}: () => import('./src/routes/${key}')`).join(" ,\n" )}
116
+ ${ files .map (( key ) => ` ${ key .split (' . ' )[0 ]} : () => import('./src/routes/${ key} ')` ).join (' ,\n ' )}
114
117
}
115
- `
118
+ ` ;
116
119
},
117
- }
120
+ },
118
121
});
119
122
```
120
123
0 commit comments