浏览代码

Merge pull request #4742 from RoccoC/webpack-plugin-esm

Update webpack plugin to support module workers
Henning Dieterichs 1 月之前
父节点
当前提交
495d075be0
共有 2 个文件被更改,包括 9 次插入2 次删除
  1. 1 1
      webpack-plugin/package.json
  2. 8 1
      webpack-plugin/src/index.ts

+ 1 - 1
webpack-plugin/package.json

@@ -1,6 +1,6 @@
 {
 {
 	"name": "monaco-editor-webpack-plugin",
 	"name": "monaco-editor-webpack-plugin",
-	"version": "7.1.0",
+	"version": "7.1.1",
 	"description": "A webpack plugin for the Monaco Editor",
 	"description": "A webpack plugin for the Monaco Editor",
 	"main": "out/index.js",
 	"main": "out/index.js",
 	"typings": "./out/index.d.ts",
 	"typings": "./out/index.d.ts",

+ 8 - 1
webpack-plugin/src/index.ts

@@ -296,7 +296,14 @@ function createLoaderRules(
               if(/^(\\/\\/)/.test(result)) {
               if(/^(\\/\\/)/.test(result)) {
                 result = window.location.protocol + 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' });
               var blob = new Blob([js], { type: 'application/javascript' });
               return URL.createObjectURL(blob);
               return URL.createObjectURL(blob);
             }
             }