mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Adopt loader-utils breaking changes
This commit is contained in:
parent
ed1ee25b7b
commit
009bc9b864
2 changed files with 26 additions and 12 deletions
|
|
@ -6,6 +6,7 @@ import { AddWorkerEntryPointPlugin } from './plugins/AddWorkerEntryPointPlugin';
|
||||||
import { languagesArr, EditorLanguage } from './languages';
|
import { languagesArr, EditorLanguage } from './languages';
|
||||||
import { featuresArr, EditorFeature, NegatedEditorFeature } from './features';
|
import { featuresArr, EditorFeature, NegatedEditorFeature } from './features';
|
||||||
import { IFeatureDefinition } from './types';
|
import { IFeatureDefinition } from './types';
|
||||||
|
import { ILoaderOptions } from './loaders/include';
|
||||||
|
|
||||||
const INCLUDE_LOADER_PATH = require.resolve('./loaders/include');
|
const INCLUDE_LOADER_PATH = require.resolve('./loaders/include');
|
||||||
|
|
||||||
|
|
@ -282,17 +283,18 @@ function createLoaderRules(
|
||||||
};
|
};
|
||||||
})(${JSON.stringify(workerPaths, null, 2)})`
|
})(${JSON.stringify(workerPaths, null, 2)})`
|
||||||
};
|
};
|
||||||
|
const options: ILoaderOptions = {
|
||||||
|
globals,
|
||||||
|
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath)),
|
||||||
|
post: languagePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath))
|
||||||
|
};
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
test: /esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/,
|
test: /esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/,
|
||||||
use: [
|
use: [
|
||||||
{
|
{
|
||||||
loader: INCLUDE_LOADER_PATH,
|
loader: INCLUDE_LOADER_PATH,
|
||||||
options: {
|
options
|
||||||
globals,
|
|
||||||
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath)),
|
|
||||||
post: languagePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
const loaderUtils = require('loader-utils');
|
import type { PitchLoaderDefinitionFunction } from 'webpack';
|
||||||
|
|
||||||
export function pitch(this: any, remainingRequest: any) {
|
export interface ILoaderOptions {
|
||||||
const { globals = undefined, pre = [], post = [] } = loaderUtils.getOptions(this) || {};
|
globals?: { [key: string]: string };
|
||||||
|
pre?: string[];
|
||||||
|
post?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = function pitch(
|
||||||
|
remainingRequest
|
||||||
|
) {
|
||||||
|
const { globals = undefined, pre = [], post = [] } = this.getOptions() || {};
|
||||||
|
|
||||||
// HACK: NamedModulesPlugin overwrites existing modules when requesting the same module via
|
// HACK: NamedModulesPlugin overwrites existing modules when requesting the same module via
|
||||||
// different loaders, so we need to circumvent this by appending a suffix to make the name unique
|
// different loaders, so we need to circumvent this by appending a suffix to make the name unique
|
||||||
|
|
@ -10,12 +18,16 @@ export function pitch(this: any, remainingRequest: any) {
|
||||||
this._module.userRequest = `include-loader!${this._module.userRequest}`;
|
this._module.userRequest = `include-loader!${this._module.userRequest}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stringifyRequest = (request: string) => {
|
||||||
|
return JSON.stringify(this.utils.contextify(this.context || this.rootContext, request));
|
||||||
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(globals
|
...(globals
|
||||||
? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
|
? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
|
||||||
: []),
|
: []),
|
||||||
...pre.map((include: any) => `require(${loaderUtils.stringifyRequest(this, include)});`),
|
...pre.map((include: any) => `require(${stringifyRequest(include)});`),
|
||||||
`module.exports = require(${loaderUtils.stringifyRequest(this, `!!${remainingRequest}`)});`,
|
`module.exports = require(${stringifyRequest(`!!${remainingRequest}`)});`,
|
||||||
...post.map((include: any) => `require(${loaderUtils.stringifyRequest(this, include)});`)
|
...post.map((include: any) => `require(${stringifyRequest(include)});`)
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue