Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable local worker file in development mode #4273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export class ExpressFileServerContribution implements ServerAppContribution {
return;
}

if (process.env.NODE_ENV === 'development' && uriPath.startsWith('/monaco/worker')) {
const filePath = path.resolve(__dirname, `../../../${uriPath}`);
const contentType = ALLOW_MIME[path.extname(filePath).slice(1)];
if (!contentType) {
ctx.status = 404;
return;
}
ctx.set('Content-Type', contentType);
ctx.body = fs.createReadStream(filePath);
return;
}

const filePath = URI.parse(`file://${uriPath}`).codeUri.fsPath;
const whitelist = this.getWhiteList();
const contentType = ALLOW_MIME[path.extname(filePath).slice(1)];
Expand Down
12 changes: 11 additions & 1 deletion packages/monaco/src/browser/monaco.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,17 @@ export class MonacoClientContribution
};

const getWorker = (moduleId, label) => {
const url = getWorkerUrl(moduleId, label);
let url: string;

/**
* 开发模式下,直接使用本地文件
*/
if (process.env.NODE_ENV === 'development') {
url = 'assets/monaco/worker/editor.worker.bundle.js';
} else {
url = getWorkerUrl(moduleId, label);
}

/**
* monaco 0.53 版本开始,创建 worker 线程时都指定了 type 为 module,而我们模块格式不兼容
* 所以需要覆写 getWorker 函数,手动创建 worker 线程
Expand Down
Loading