fix(monaco-editor-webpack-plugin): load monaco-editor with webpack 4

Closes #2817
This commit is contained in:
ValeraS 2021-12-12 01:17:34 +03:00
parent 3e433551a9
commit 3ae92d5f1a
4 changed files with 21 additions and 14 deletions

View file

@ -1,3 +1,5 @@
declare module 'loader-utils' {
export function interpolateName(loaderContext: any, name: string, options?: any): string;
export function stringifyRequest(loaderContext: any, resource: string): string;
}

View file

@ -1,4 +1,5 @@
import type { PitchLoaderDefinitionFunction } from 'webpack';
import * as loaderUtils from 'loader-utils';
export interface ILoaderOptions {
globals?: { [key: string]: string };
@ -9,7 +10,7 @@ export interface ILoaderOptions {
export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = function pitch(
remainingRequest
) {
const { globals = undefined, pre = [], post = [] } = this.getOptions() || {};
const { globals = undefined, pre = [], post = [] } = (this.query as ILoaderOptions) || {};
// 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
@ -19,7 +20,10 @@ export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = function pit
}
const stringifyRequest = (request: string) => {
return JSON.stringify(this.utils.contextify(this.context || this.rootContext, request));
if (this.utils) {
return JSON.stringify(this.utils.contextify(this.context || this.rootContext, request));
}
return loaderUtils.stringifyRequest(this, request);
};
return [