From 213f1821ecc124887faed3a4064190dc710e52e9 Mon Sep 17 00:00:00 2001 From: ValeraS Date: Thu, 30 Dec 2021 17:16:33 +0300 Subject: [PATCH 1/3] tune(monaco-editor-webpack-plugin): replace editor.main.js Replace editor.main.js with editor.api.js and requested features and languages --- samples/browser-esm-webpack-monaco-plugin/index.js | 2 +- webpack-plugin/src/loaders/include.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/browser-esm-webpack-monaco-plugin/index.js b/samples/browser-esm-webpack-monaco-plugin/index.js index 712ccd1f..27c82f59 100644 --- a/samples/browser-esm-webpack-monaco-plugin/index.js +++ b/samples/browser-esm-webpack-monaco-plugin/index.js @@ -1,4 +1,4 @@ -import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; +import * as monaco from 'monaco-editor'; (function () { // create div to avoid needing a HtmlWebpackPlugin template diff --git a/webpack-plugin/src/loaders/include.ts b/webpack-plugin/src/loaders/include.ts index 4bebcce9..1b4a0e95 100644 --- a/webpack-plugin/src/loaders/include.ts +++ b/webpack-plugin/src/loaders/include.ts @@ -26,14 +26,16 @@ export const pitch: PitchLoaderDefinitionFunction = function pit return loaderUtils.stringifyRequest(this, request); }; + // editor.main.js contains all features and languages, replace it with requested features, languages and editor.api.js + const apiRequest = remainingRequest.replace(/editor\.main\.js$/, 'editor.api.js'); return [ ...(globals ? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`) : []), ...pre.map((include: any) => `import ${stringifyRequest(include)};`), ` -import * as monaco from ${stringifyRequest(`!!${remainingRequest}`)}; -export * from ${stringifyRequest(`!!${remainingRequest}`)}; +import * as monaco from ${stringifyRequest(`!!${apiRequest}`)}; +export * from ${stringifyRequest(`!!${apiRequest}`)}; export default monaco; `, ...post.map((include: any) => `import ${stringifyRequest(include)};`) From 82b5487f2b4a4a60b5c3d4f46f24cad5d72ef353 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Thu, 3 Feb 2022 16:13:59 +0100 Subject: [PATCH 2/3] Import monaco-editor instead of editor.api. --- test/smoke/webpack/index.js | 2 +- webpack-plugin/README.md | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/smoke/webpack/index.js b/test/smoke/webpack/index.js index f4e62ee8..edcd18b6 100644 --- a/test/smoke/webpack/index.js +++ b/test/smoke/webpack/index.js @@ -1,4 +1,4 @@ -import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; +import * as monaco from 'monaco-editor'; // expose the monaco API as a global for tests window.monacoAPI = monaco; diff --git a/webpack-plugin/README.md b/webpack-plugin/README.md index e97f5c9e..1301252e 100644 --- a/webpack-plugin/README.md +++ b/webpack-plugin/README.md @@ -51,8 +51,6 @@ If using Webpack 4 or lower, it is necessary to use the file-loader instead of A ```js import * as monaco from 'monaco-editor'; -// or import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; -// if shipping only a subset of the features & languages is desired monaco.editor.create(document.getElementById('container'), { value: 'console.log("Hello, world")', From 2d605304f5414be015b417b546c500340978aefc Mon Sep 17 00:00:00 2001 From: ValeraS Date: Fri, 4 Feb 2022 01:39:47 +0300 Subject: [PATCH 3/3] transform only editor.main.js BREAKING CHANGES: if a project contains only these imports for creating editor: ``` import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'; const editor = monaco.editor.create(...); ``` `monaco-editor-webpack-plugin` will not add features and languages. When creating editor, monaco must be imported from package itself: ``` import * as monaco from 'monaco-editor'; const editor = monaco.editor.create(...); ``` --- webpack-plugin/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack-plugin/src/index.ts b/webpack-plugin/src/index.ts index 529dd044..163be971 100644 --- a/webpack-plugin/src/index.ts +++ b/webpack-plugin/src/index.ts @@ -313,7 +313,7 @@ function createLoaderRules( }; return [ { - test: /esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/, + test: /esm[/\\]vs[/\\]editor[/\\]editor.main.js/, use: [ { loader: INCLUDE_LOADER_PATH,