Skip to content

Commit 0d6ddb8

Browse files
authored
chore: enable local worker file in development mode (#4273)
1 parent 5355b54 commit 0d6ddb8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/express-file-server/src/node/express-file-server.contribution.ts

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ export class ExpressFileServerContribution implements ServerAppContribution {
3030
return;
3131
}
3232

33+
if (process.env.NODE_ENV === 'development' && uriPath.startsWith('/monaco/worker')) {
34+
const filePath = path.resolve(__dirname, `../../../${uriPath}`);
35+
const contentType = ALLOW_MIME[path.extname(filePath).slice(1)];
36+
if (!contentType) {
37+
ctx.status = 404;
38+
return;
39+
}
40+
ctx.set('Content-Type', contentType);
41+
ctx.body = fs.createReadStream(filePath);
42+
return;
43+
}
44+
3345
const filePath = URI.parse(`file://${uriPath}`).codeUri.fsPath;
3446
const whitelist = this.getWhiteList();
3547
const contentType = ALLOW_MIME[path.extname(filePath).slice(1)];

packages/monaco/src/browser/monaco.contribution.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,17 @@ export class MonacoClientContribution
301301
};
302302

303303
const getWorker = (moduleId, label) => {
304-
const url = getWorkerUrl(moduleId, label);
304+
let url: string;
305+
306+
/**
307+
* 开发模式下,直接使用本地文件
308+
*/
309+
if (process.env.NODE_ENV === 'development') {
310+
url = 'assets/monaco/worker/editor.worker.bundle.js';
311+
} else {
312+
url = getWorkerUrl(moduleId, label);
313+
}
314+
305315
/**
306316
* monaco 0.53 版本开始,创建 worker 线程时都指定了 type 为 module,而我们模块格式不兼容
307317
* 所以需要覆写 getWorker 函数,手动创建 worker 线程

0 commit comments

Comments
 (0)