@meethive/vite 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{src/federation/src/runtime/dynamic-remote.d.ts → dynamic-remote.d.ts} +25 -19
- package/dist/dynamic-remote.js +185 -0
- package/dist/dynamic-remote.mjs +163 -0
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1 -20
- package/dist/index.mjs +1 -20
- package/dist/{src/federation/src/utils/semver/satisfy.d.ts → satisfy.d.ts} +2 -1
- package/dist/satisfy.js +381 -0
- package/dist/satisfy.mjs +381 -0
- package/package.json +20 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/src/federation/src/dev/expose-development.d.ts +0 -5
- package/dist/src/federation/src/dev/expose-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/remote-development.d.ts +0 -5
- package/dist/src/federation/src/dev/remote-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/shared-development.d.ts +0 -5
- package/dist/src/federation/src/dev/shared-development.d.ts.map +0 -1
- package/dist/src/federation/src/index.d.ts +0 -7
- package/dist/src/federation/src/index.d.ts.map +0 -1
- package/dist/src/federation/src/prod/expose-production.d.ts +0 -5
- package/dist/src/federation/src/prod/expose-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/remote-production.d.ts +0 -7
- package/dist/src/federation/src/prod/remote-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/shared-production.d.ts +0 -5
- package/dist/src/federation/src/prod/shared-production.d.ts.map +0 -1
- package/dist/src/federation/src/public.d.ts +0 -40
- package/dist/src/federation/src/public.d.ts.map +0 -1
- package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +0 -1
- package/dist/src/federation/src/utils/html.d.ts +0 -12
- package/dist/src/federation/src/utils/html.d.ts.map +0 -1
- package/dist/src/federation/src/utils/index.d.ts +0 -29
- package/dist/src/federation/src/utils/index.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/compare.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/compare.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/constants.d.ts +0 -11
- package/dist/src/federation/src/utils/semver/constants.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/parser.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/parser.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/utils.d.ts +0 -12
- package/dist/src/federation/src/utils/semver/utils.d.ts.map +0 -1
- package/dist/src/monaco-editor/index.d.ts +0 -35
- package/dist/src/monaco-editor/index.d.ts.map +0 -1
- package/dist/src/monaco-editor/languageWork.d.ts +0 -10
- package/dist/src/monaco-editor/languageWork.d.ts.map +0 -1
- package/dist/src/monaco-editor/workerMiddleware.d.ts +0 -9
- package/dist/src/monaco-editor/workerMiddleware.d.ts.map +0 -1
- package/dist/src/sharp/index.d.ts +0 -12
- package/dist/src/sharp/index.d.ts.map +0 -1
- package/index.ts +0 -3
- package/src/federation/src/dev/expose-development.ts +0 -29
- package/src/federation/src/dev/remote-development.ts +0 -435
- package/src/federation/src/dev/shared-development.ts +0 -29
- package/src/federation/src/index.ts +0 -242
- package/src/federation/src/prod/expose-production.ts +0 -333
- package/src/federation/src/prod/federation_fn_import.js +0 -75
- package/src/federation/src/prod/remote-production.ts +0 -658
- package/src/federation/src/prod/shared-production.ts +0 -268
- package/src/federation/src/public.ts +0 -54
- package/src/federation/src/runtime/dynamic-remote.ts +0 -247
- package/src/federation/src/utils/html.ts +0 -165
- package/src/federation/src/utils/index.ts +0 -255
- package/src/federation/src/utils/semver/compare.ts +0 -131
- package/src/federation/src/utils/semver/constants.ts +0 -46
- package/src/federation/src/utils/semver/parser.ts +0 -253
- package/src/federation/src/utils/semver/satisfy.ts +0 -151
- package/src/federation/src/utils/semver/utils.ts +0 -93
- package/src/federation/types/dynamic-remote.d.ts +0 -105
- package/src/federation/types/index.d.ts +0 -344
- package/src/federation/types/pluginHooks.d.ts +0 -4
- package/src/federation/types/virtual-modules.d.ts +0 -48
- package/src/federation/types/viteDevServer.d.ts +0 -22
- package/src/monaco-editor/index.ts +0 -205
- package/src/monaco-editor/languageWork.ts +0 -36
- package/src/monaco-editor/workerMiddleware.ts +0 -78
- package/src/sharp/index.ts +0 -93
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The following code is adapted from https://github.com/webpack/webpack/types.d.ts
|
|
3
|
-
* MIT License https://github.com/webpack/webpack/LICENSE
|
|
4
|
-
*/
|
|
5
|
-
import { RenderedChunk } from 'rollup'
|
|
6
|
-
|
|
7
|
-
export { VitePluginFederationVersion } from '../src/public'
|
|
8
|
-
export * from '../src/runtime/dynamic-remote'
|
|
9
|
-
export default function federation(options: VitePluginFederationOptions): Plugin
|
|
10
|
-
|
|
11
|
-
export declare interface VitePluginFederationOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
|
|
14
|
-
*/
|
|
15
|
-
exposes?: Exposes
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The filename of the container as relative path inside the `output.path` directory.
|
|
19
|
-
*/
|
|
20
|
-
filename?: string
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* transform hook need to handle file types
|
|
24
|
-
* default ['.js','.ts','.jsx','.tsx','.mjs','.cjs','.vue','.svelte']
|
|
25
|
-
*/
|
|
26
|
-
transformFileTypes?: string[]
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Options for library.
|
|
30
|
-
*/
|
|
31
|
-
// library?: LibraryOptions
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The name of the container.
|
|
35
|
-
*/
|
|
36
|
-
name?: string
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The external type of the remote containers.
|
|
40
|
-
*/
|
|
41
|
-
remoteType?:
|
|
42
|
-
| 'var'
|
|
43
|
-
| 'module'
|
|
44
|
-
| 'assign'
|
|
45
|
-
| 'this'
|
|
46
|
-
| 'window'
|
|
47
|
-
| 'self'
|
|
48
|
-
| 'global'
|
|
49
|
-
| 'commonjs'
|
|
50
|
-
| 'commonjs2'
|
|
51
|
-
| 'commonjs-module'
|
|
52
|
-
| 'amd'
|
|
53
|
-
| 'amd-require'
|
|
54
|
-
| 'umd'
|
|
55
|
-
| 'umd2'
|
|
56
|
-
| 'jsonp'
|
|
57
|
-
| 'system'
|
|
58
|
-
| 'promise'
|
|
59
|
-
| 'import'
|
|
60
|
-
| 'script'
|
|
61
|
-
| 'node-commonjs'
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.
|
|
65
|
-
*/
|
|
66
|
-
remotes?: Remotes
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Enable dynamic remote loading support. When enabled, virtual:__federation__ module will be available even without static remotes configuration.
|
|
70
|
-
*/
|
|
71
|
-
enableDynamicRemotes?: boolean
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.
|
|
75
|
-
*/
|
|
76
|
-
// runtime?: string | false
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Share scope name used for all shared modules (defaults to 'default').
|
|
80
|
-
*/
|
|
81
|
-
shareScope?: string
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.
|
|
85
|
-
*/
|
|
86
|
-
shared?: Shared
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Current operating mode
|
|
90
|
-
*/
|
|
91
|
-
mode?: string
|
|
92
|
-
|
|
93
|
-
isHost?: boolean
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type Exposes = (string | ExposesObject)[] | ExposesObject
|
|
97
|
-
|
|
98
|
-
export type Remotes = (string | RemotesObject)[] | RemotesObject
|
|
99
|
-
|
|
100
|
-
export type Shared = (string | SharedObject)[] | SharedObject
|
|
101
|
-
|
|
102
|
-
export type ConfigTypeSet = ExposesConfig | RemotesConfig | SharedConfig
|
|
103
|
-
|
|
104
|
-
declare interface SharedRuntimeInfo {
|
|
105
|
-
id: string
|
|
106
|
-
dependencies: string[]
|
|
107
|
-
fileName: string
|
|
108
|
-
fileDir: string
|
|
109
|
-
filePath: string
|
|
110
|
-
chunk: RenderedChunk
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Modules that should be exposed by this container. Property names are used as public paths.
|
|
115
|
-
*/
|
|
116
|
-
declare interface ExposesObject {
|
|
117
|
-
[index: string]: ExposesConfig | string | string[]
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Advanced configuration for modules that should be exposed by this container.
|
|
122
|
-
*/
|
|
123
|
-
declare interface ExposesConfig {
|
|
124
|
-
/**
|
|
125
|
-
* Request to a module that should be exposed by this container.
|
|
126
|
-
*/
|
|
127
|
-
import: string
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Custom chunk name for the exposed module.
|
|
131
|
-
*/
|
|
132
|
-
name?: string
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* If false, the link element with styles is put in <head> element. If true, the href argument of all links objects
|
|
136
|
-
* are put under global window object and can be retrieved by the component. It's for using with ShadowDOM, when
|
|
137
|
-
* the component must place the styles inside the ShadowDOM instead of the <head> element.
|
|
138
|
-
*/
|
|
139
|
-
dontAppendStylesToHead?: boolean
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Options for library.
|
|
144
|
-
*/
|
|
145
|
-
declare interface LibraryOptions {
|
|
146
|
-
/**
|
|
147
|
-
* Add a comment in the UMD wrapper.
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
auxiliaryComment?: string | LibraryCustomUmdCommentObject
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Specify which export should be exposed as library.
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
export?: string | string[]
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The name of the library (some types allow unnamed libraries too).
|
|
160
|
-
*
|
|
161
|
-
*/
|
|
162
|
-
name?: string | string[] | LibraryCustomUmdObject
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
|
|
166
|
-
*
|
|
167
|
-
*/
|
|
168
|
-
type: string
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.
|
|
172
|
-
*
|
|
173
|
-
*/
|
|
174
|
-
umdNamedDefine?: boolean
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.
|
|
179
|
-
*/
|
|
180
|
-
declare interface LibraryCustomUmdCommentObject {
|
|
181
|
-
/**
|
|
182
|
-
* Set comment for `amd` section in UMD.
|
|
183
|
-
*/
|
|
184
|
-
amd?: string
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Set comment for `commonjs` (exports) section in UMD.
|
|
188
|
-
*/
|
|
189
|
-
commonjs?: string
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Set comment for `commonjs2` (module.exports) section in UMD.
|
|
193
|
-
*/
|
|
194
|
-
commonjs2?: string
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Set comment for `root` (global variable) section in UMD.
|
|
198
|
-
*/
|
|
199
|
-
root?: string
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Description object for all UMD variants of the library name.
|
|
204
|
-
*/
|
|
205
|
-
declare interface LibraryCustomUmdObject {
|
|
206
|
-
/**
|
|
207
|
-
* Name of the exposed AMD library in the UMD.
|
|
208
|
-
*/
|
|
209
|
-
amd?: string
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Name of the exposed commonjs export in the UMD.
|
|
213
|
-
*/
|
|
214
|
-
commonjs?: string
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Name of the property exposed globally by a UMD library.
|
|
218
|
-
*/
|
|
219
|
-
root?: string | string[]
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Container locations from which modules should be resolved and loaded at runtime. Property names are used as request scopes.
|
|
224
|
-
*/
|
|
225
|
-
declare interface RemotesObject {
|
|
226
|
-
[index: string]: string | RemotesConfig | string[] | Promise<any>
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Advanced configuration for container locations from which modules should be resolved and loaded at runtime.
|
|
231
|
-
*/
|
|
232
|
-
export declare interface RemotesConfig {
|
|
233
|
-
/**
|
|
234
|
-
* Container locations from which modules should be resolved and loaded at runtime.
|
|
235
|
-
*/
|
|
236
|
-
external: string
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* The format of the specified external
|
|
240
|
-
*/
|
|
241
|
-
externalType: 'url' | 'promise'
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* The name of the share scope shared with this remote.
|
|
245
|
-
*/
|
|
246
|
-
shareScope?: string
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* the remote format
|
|
250
|
-
*/
|
|
251
|
-
format?: 'esm' | 'systemjs' | 'var'
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* from
|
|
255
|
-
*/
|
|
256
|
-
from?: 'vite' | 'webpack'
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Modules that should be shared in the share scope. Property names are used to match requested modules in this compilation. Relative requests are resolved, module requests are matched unresolved, absolute paths will match resolved requests. A trailing slash will match all requests with this prefix. In this case shareKey must also have a trailing slash.
|
|
261
|
-
*/
|
|
262
|
-
declare interface SharedObject {
|
|
263
|
-
[index: string]: string | SharedConfig
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Advanced configuration for modules that should be shared in the share scope.
|
|
268
|
-
*/
|
|
269
|
-
declare interface SharedConfig {
|
|
270
|
-
/**
|
|
271
|
-
* Include the provided and fallback module directly instead behind an async request. This allows to use this shared module in initial load too. All possible shared modules need to be eager too.
|
|
272
|
-
*/
|
|
273
|
-
// eager?: boolean
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Provided module that should be provided to share scope. Also acts as fallback module if no shared module is found in share scope or version isn't valid. Defaults to the property name.
|
|
277
|
-
*/
|
|
278
|
-
import?: boolean
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Package name to determine required version from description file. This is only needed when package name can't be automatically determined from request.
|
|
282
|
-
*/
|
|
283
|
-
// packageName?: string
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Specify the path to the custom package, the field is not supported in dev mode
|
|
287
|
-
*/
|
|
288
|
-
packagePath?: string | undefined
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Version requirement from module in share scope.
|
|
292
|
-
*/
|
|
293
|
-
requiredVersion?: string | false
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Module is looked up under this key from the share scope.
|
|
297
|
-
*/
|
|
298
|
-
// shareKey?: string
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Share scope name.
|
|
302
|
-
*/
|
|
303
|
-
shareScope?: string
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Allow only a single version of the shared module in share scope (disabled by default).
|
|
307
|
-
*/
|
|
308
|
-
// singleton?: boolean
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).
|
|
312
|
-
*/
|
|
313
|
-
// strictVersion?: boolean
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Version of the provided module. Will replace lower matching versions, but not higher.
|
|
317
|
-
*/
|
|
318
|
-
version?: string | false
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* determine whether to include the shared in the chunk, true is included, false will not generate a shared chunk, only the remote side of the parameter is valid, the host side will definitely generate a shared chunk
|
|
322
|
-
*/
|
|
323
|
-
generate?: boolean
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* if true, the shared dep will be append in the html head, only valid in prod mode
|
|
327
|
-
*/
|
|
328
|
-
modulePreload?: boolean
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
declare module "virtual:__federation__" {
|
|
332
|
-
function __federation_method_getRemote(name: string, url: string): Promise<any>
|
|
333
|
-
function __federation_method_setRemote(name: string, config: any): void
|
|
334
|
-
function __federation_method_add_origin_setRemote(name: string, url: string, options?: {
|
|
335
|
-
external?: string | string[];
|
|
336
|
-
shareScope?: string;
|
|
337
|
-
format?: 'esm' | 'systemjs' | 'var';
|
|
338
|
-
from?: 'vite' | 'webpack';
|
|
339
|
-
externalType?: 'url' | 'promise';
|
|
340
|
-
}): void
|
|
341
|
-
function __federation_method_unwrapDefault(info: any): any
|
|
342
|
-
function __federation_method_wrapDefault(module: any, need: boolean): any
|
|
343
|
-
function __federation_method_ensure(remoteName: string): Promise<any>
|
|
344
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
declare module "virtual:__federation__" {
|
|
2
|
-
/**
|
|
3
|
-
* Get remote component dynamically
|
|
4
|
-
* @param name Remote name
|
|
5
|
-
* @param url Remote URL or config
|
|
6
|
-
*/
|
|
7
|
-
function __federation_method_getRemote(name: string, url: string): Promise<any>
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Set remote configuration
|
|
11
|
-
* @param name Remote name
|
|
12
|
-
* @param config Remote configuration object
|
|
13
|
-
*/
|
|
14
|
-
function __federation_method_setRemote(name: string, config: any): void
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Add remote with configuration dynamically
|
|
18
|
-
* @param name Remote name
|
|
19
|
-
* @param url Remote URL
|
|
20
|
-
* @param options Remote configuration options
|
|
21
|
-
*/
|
|
22
|
-
function __federation_method_add_origin_setRemote(name: string, url: string, options?: {
|
|
23
|
-
external?: string | string[];
|
|
24
|
-
shareScope?: string;
|
|
25
|
-
format?: 'esm' | 'systemjs' | 'var';
|
|
26
|
-
from?: 'vite' | 'webpack';
|
|
27
|
-
externalType?: 'url' | 'promise';
|
|
28
|
-
}): void
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Unwrap default export from module
|
|
32
|
-
* @param info Module object
|
|
33
|
-
*/
|
|
34
|
-
function __federation_method_unwrapDefault(info: any): any
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Wrap module with default export if needed
|
|
38
|
-
* @param module Module object
|
|
39
|
-
* @param need Whether to wrap with default
|
|
40
|
-
*/
|
|
41
|
-
function __federation_method_wrapDefault(module: any, need: boolean): any
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Ensure remote is loaded and initialized
|
|
45
|
-
* @param remoteName Remote name
|
|
46
|
-
*/
|
|
47
|
-
function __federation_method_ensure(remoteName: string): Promise<any>
|
|
48
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ViteDevServer as Config } from 'vite'
|
|
2
|
-
|
|
3
|
-
export interface ViteDevServer extends Config {
|
|
4
|
-
_optimizeDepsMetadata?: {
|
|
5
|
-
hash: string
|
|
6
|
-
browserHash: string
|
|
7
|
-
optimized: Map<string, Optimized>
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare interface Optimized {
|
|
12
|
-
file: string
|
|
13
|
-
src: string
|
|
14
|
-
needsInterop: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Hostname {
|
|
18
|
-
// undefined sets the default behaviour of server.listen
|
|
19
|
-
host: string | undefined
|
|
20
|
-
// resolve to localhost when possible
|
|
21
|
-
name: string
|
|
22
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { HtmlTagDescriptor, Plugin, ResolvedConfig } from 'vite';
|
|
2
|
-
import { resolve, join } from 'path';
|
|
3
|
-
import { buildSync } from 'esbuild'
|
|
4
|
-
|
|
5
|
-
import { EditorLanguageWorks, IWorkerDefinition, languageWorksByLabel } from './languageWork';
|
|
6
|
-
import { workerMiddleware, cacheDir, getFilenameByEntry, getWorkPath } from './workerMiddleware';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Return a resolved path for a given Monaco file.
|
|
10
|
-
*/
|
|
11
|
-
export function resolveMonacoPath(filePath: string): string {
|
|
12
|
-
try {
|
|
13
|
-
return resolve(join(process.cwd(), 'node_modules', filePath));
|
|
14
|
-
} catch (err) {
|
|
15
|
-
return resolve(filePath);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getWorks(options: IMonacoEditorOpts) {
|
|
20
|
-
let works: IWorkerDefinition[] = options.languageWorkers.map(
|
|
21
|
-
(work) => languageWorksByLabel[work]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
works.push(...options.customWorkers);
|
|
25
|
-
|
|
26
|
-
return works;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IMonacoEditorOpts {
|
|
30
|
-
/**
|
|
31
|
-
* include only a subset of the languageWorkers supported.
|
|
32
|
-
*/
|
|
33
|
-
languageWorkers?: EditorLanguageWorks[];
|
|
34
|
-
|
|
35
|
-
customWorkers?: IWorkerDefinition[];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Override the public path from which files generated by this plugin will be served.
|
|
39
|
-
* This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-
|
|
40
|
-
* origin when using a CDN for other static resources.
|
|
41
|
-
* Use e.g. '/' if you want to load your resources from the current origin.
|
|
42
|
-
*/
|
|
43
|
-
publicPath?: string;
|
|
44
|
-
|
|
45
|
-
customDistPath?: (root: string, buildOutDir: string, base: string) => string;
|
|
46
|
-
|
|
47
|
-
forceBuildCDN?: boolean;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Specify whether the editor API should be exposed through a global `monaco` object or not. This
|
|
51
|
-
* option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM
|
|
52
|
-
* version of the monaco editor does no longer define a global `monaco` object unless
|
|
53
|
-
* `global.MonacoEnvironment = { globalAPI: true }` is set ([change
|
|
54
|
-
* log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
|
|
55
|
-
*/
|
|
56
|
-
globalAPI?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const getFS = async () => {
|
|
60
|
-
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
61
|
-
const fs = await import('fs');
|
|
62
|
-
return {
|
|
63
|
-
existsSync: fs.existsSync,
|
|
64
|
-
mkdirSync: fs.mkdirSync,
|
|
65
|
-
readFileSync: fs.readFileSync,
|
|
66
|
-
writeFileSync: fs.writeFileSync
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export default function monacoEditorPlugin(options: IMonacoEditorOpts): Plugin {
|
|
73
|
-
const languageWorkers =
|
|
74
|
-
options.languageWorkers || (Object.keys(languageWorksByLabel) as EditorLanguageWorks[]);
|
|
75
|
-
const publicPath = options.publicPath || 'monacoeditorwork';
|
|
76
|
-
const globalAPI = options.globalAPI || false;
|
|
77
|
-
const customWorkers = options.customWorkers || [];
|
|
78
|
-
const forceBuildCDN = options.forceBuildCDN || false;
|
|
79
|
-
|
|
80
|
-
options = {
|
|
81
|
-
...options,
|
|
82
|
-
languageWorkers,
|
|
83
|
-
publicPath,
|
|
84
|
-
globalAPI,
|
|
85
|
-
customWorkers,
|
|
86
|
-
forceBuildCDN,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
let resolvedConfig: ResolvedConfig;
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
name: 'vite-plugin-monaco-editor',
|
|
93
|
-
configResolved(getResolvedConfig) {
|
|
94
|
-
resolvedConfig = getResolvedConfig;
|
|
95
|
-
},
|
|
96
|
-
configureServer(server) {
|
|
97
|
-
if (isCDN(publicPath)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
workerMiddleware(server.middlewares, resolvedConfig, options);
|
|
102
|
-
},
|
|
103
|
-
transformIndexHtml(html) {
|
|
104
|
-
const works = getWorks(options);
|
|
105
|
-
const workerPaths = getWorkPath(works, options, resolvedConfig);
|
|
106
|
-
|
|
107
|
-
const globals = {
|
|
108
|
-
MonacoEnvironment: `(function (paths) {
|
|
109
|
-
return {
|
|
110
|
-
globalAPI: ${globalAPI},
|
|
111
|
-
getWorkerUrl : function (moduleId, label) {
|
|
112
|
-
var result = paths[label];
|
|
113
|
-
var _location = window.__MICRO_APP_ENVIRONMENT__ ? window.rawWindow.location : window.location;
|
|
114
|
-
var currentUrl = String(_location);
|
|
115
|
-
var currentOrigin = currentUrl.substr(0, currentUrl.length - _location.hash.length - _location.search.length - _location.pathname.length);
|
|
116
|
-
|
|
117
|
-
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
118
|
-
result = currentOrigin + result.replace('./', '/')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
|
|
122
|
-
if (result.substring(0, currentOrigin.length) !== currentOrigin) {
|
|
123
|
-
var js = '/*' + label + '*/importScripts("' + result + '");';
|
|
124
|
-
var blob = new Blob([js], { type: 'application/javascript' });
|
|
125
|
-
return URL.createObjectURL(blob);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
console.log('result',result);
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
})(${JSON.stringify(workerPaths, null, 2)})`,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const descriptor: HtmlTagDescriptor[] = [
|
|
136
|
-
{
|
|
137
|
-
tag: 'script',
|
|
138
|
-
children: Object.keys(globals)
|
|
139
|
-
.map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
|
|
140
|
-
.join('\n'),
|
|
141
|
-
injectTo: 'head-prepend',
|
|
142
|
-
},
|
|
143
|
-
];
|
|
144
|
-
return descriptor;
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
async writeBundle() {
|
|
148
|
-
// 是cdn地址并且没有强制构建worker cdn则返回
|
|
149
|
-
if (isCDN(publicPath) && !forceBuildCDN) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const fs = await getFS();
|
|
154
|
-
if (!fs) {
|
|
155
|
-
this.warn('File system operations not available in this environment');
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const works = getWorks(options);
|
|
160
|
-
|
|
161
|
-
const distPath = options.customDistPath
|
|
162
|
-
? options.customDistPath(
|
|
163
|
-
resolvedConfig.root,
|
|
164
|
-
resolvedConfig.build.outDir,
|
|
165
|
-
resolvedConfig.base
|
|
166
|
-
)
|
|
167
|
-
: join(
|
|
168
|
-
resolvedConfig.root,
|
|
169
|
-
resolvedConfig.build.outDir,
|
|
170
|
-
resolvedConfig.base,
|
|
171
|
-
options.publicPath
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
// console.log("distPath", distPath)
|
|
175
|
-
|
|
176
|
-
// write publicPath
|
|
177
|
-
if (!fs.existsSync(distPath)) {
|
|
178
|
-
fs.mkdirSync(distPath, {
|
|
179
|
-
recursive: true,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
for (const work of works) {
|
|
184
|
-
if (!fs.existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
185
|
-
buildSync({
|
|
186
|
-
entryPoints: [resolveMonacoPath(work.entry)],
|
|
187
|
-
bundle: true,
|
|
188
|
-
outfile: cacheDir + getFilenameByEntry(work.entry),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
const contentBuffer = fs.readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
192
|
-
const workDistPath = resolve(distPath, getFilenameByEntry(work.entry));
|
|
193
|
-
fs.writeFileSync(workDistPath, contentBuffer);
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function isCDN(publicPath: string) {
|
|
200
|
-
if (/^((http:)|(https:)|(file:)|(\/\/))/.test(publicPath)) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface IWorkerDefinition {
|
|
2
|
-
label: string;
|
|
3
|
-
entry: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const languageWorkAttr: IWorkerDefinition[] = [
|
|
7
|
-
{
|
|
8
|
-
label: 'editorWorkerService',
|
|
9
|
-
entry: 'monaco-editor/esm/vs/editor/editor.worker',
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
label: 'css',
|
|
13
|
-
entry: 'monaco-editor/esm/vs/language/css/css.worker',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
label: 'html',
|
|
17
|
-
entry: 'monaco-editor/esm/vs/language/html/html.worker',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
label: 'json',
|
|
21
|
-
entry: 'monaco-editor/esm/vs/language/json/json.worker',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
label: 'typescript',
|
|
25
|
-
entry: 'monaco-editor/esm/vs/language/typescript/ts.worker',
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const languageWorksByLabel: { [language: string]: IWorkerDefinition } = {};
|
|
31
|
-
languageWorkAttr.forEach(
|
|
32
|
-
(languageWork) => (languageWorksByLabel[languageWork.label] = languageWork)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export type EditorLanguageWorks = 'css' | 'html' | 'json' | 'typescript' | 'editorWorkerService'
|