From ae5cab77cb1789abfbb83e5b462be83ec8bbaea0 Mon Sep 17 00:00:00 2001 From: RoccoC Date: Tue, 5 Nov 2024 12:07:29 -0800 Subject: [PATCH] update webpack plugin to support module workers --- webpack-plugin/package.json | 2 +- webpack-plugin/src/index.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/webpack-plugin/package.json b/webpack-plugin/package.json index 48e5e1350a..07ac8fed6f 100644 --- a/webpack-plugin/package.json +++ b/webpack-plugin/package.json @@ -1,6 +1,6 @@ { "name": "monaco-editor-webpack-plugin", - "version": "7.1.0", + "version": "7.1.1", "description": "A webpack plugin for the Monaco Editor", "main": "out/index.js", "typings": "./out/index.d.ts", diff --git a/webpack-plugin/src/index.ts b/webpack-plugin/src/index.ts index 529dd044c5..ea8ca29313 100644 --- a/webpack-plugin/src/index.ts +++ b/webpack-plugin/src/index.ts @@ -296,7 +296,14 @@ function createLoaderRules( if(/^(\\/\\/)/.test(result)) { result = window.location.protocol + result } - var js = '/*' + label + '*/importScripts("' + result + '");'; + var js = '/*' + label + '*/'; + if (typeof import.meta !== 'undefined') { + // module worker + js += 'import "' + result + '";'; + } else { + // classic worker + js += 'importScripts("' + result + '");'; + } var blob = new Blob([js], { type: 'application/javascript' }); return URL.createObjectURL(blob); }