Skip to content

tune(monaco-editor-webpack-plugin): replace editor.main.js #2865

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

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion samples/browser-esm-webpack-monaco-plugin/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/webpack/index.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 0 additions & 2 deletions webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")',
Expand Down
2 changes: 1 addition & 1 deletion webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions webpack-plugin/src/loaders/include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = 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)};`)
Expand Down