-
Notifications
You must be signed in to change notification settings - Fork 2
/
monaco.js
58 lines (54 loc) · 1.98 KB
/
monaco.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const path = require('path');
const loaderUtils = require('loader-utils');
module.exports.pitch = function pitch(remainingRequest) {
const { modules = [], workers = [], workerOptions = {} } = loaderUtils.getOptions(this) || {};
return `
(function(workerUrls) {
(global.MonacoEnvironment || (global.MonacoEnvironment = {})).getWorkerUrl = function(workerId, label) {
var baseUrl = (typeof global.MonacoEnvironment.baseUrl === "string"
? global.MonacoEnvironment.baseUrl
: ${typeof workerOptions.baseUrl === 'string' ? JSON.stringify(workerOptions.baseUrl) : '__webpack_public_path__'}
).replace(/\\/$/, '');
var scriptPath = workerId in workerUrls ? workerUrls[workerId] : workerId;
var isAbsolutePath = /^(\\w+:|\\/)/.test(scriptPath);
return (baseUrl && !isAbsolutePath ? baseUrl + "/" : "") + scriptPath + "#" + label;
};
}({${
workers.map(
(worker) => `${
JSON.stringify(worker.name)
}: require(${
loaderUtils.stringifyRequest(this, getWorkerPath(worker, workerOptions))
})`
).join(',\n')
}}))
var main = require(${loaderUtils.stringifyRequest(this, `!!${remainingRequest}`)});
${
getModuleEntryPoints(modules).map(
(entry) => `require(${loaderUtils.stringifyRequest(this, entry)});`
).join('\n')
}
module.exports = main;`;
};
function getModuleEntryPoints(modules) {
return modules.filter((module) => Boolean(module.include))
.map((module) => path.join(module.root, module.main));
}
function getWorkerPath(worker, { inline, baseUrl, filename }) {
return `${
inline
? `${require.resolve('./blobUrl')}?${JSON.stringify({
type: 'application/javascript',
sourceMap: false,
})}`
: `${require.resolve('./chunkUrl')}?${JSON.stringify({
publicPath: baseUrl,
})}`
}!${require.resolve('./compile')}?${JSON.stringify({
target: 'worker',
emit: !inline,
output: filename,
})}!${require.resolve('./include')}?${JSON.stringify({
includes: worker.includes,
})}!${worker.main}`;
}