Merge pull request #2853 from ValeraS/webpack-plugin

tune(monaco-editor-webpack-plugin): expose plugin options type
This commit is contained in:
Alexandru Dima 2022-01-14 09:52:53 +01:00 committed by GitHub
commit c9e1c9962b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,53 +99,54 @@ function resolveDesiredLanguages(
return coalesce(languages.map((id) => languagesById[id])).concat(userCustomLanguages || []); return coalesce(languages.map((id) => languagesById[id])).concat(userCustomLanguages || []);
} }
interface IMonacoEditorWebpackPluginOpts { declare namespace MonacoEditorWebpackPlugin {
/** interface IMonacoEditorWebpackPluginOpts {
* Include only a subset of the languages supported. /**
*/ * Include only a subset of the languages supported.
languages?: EditorLanguage[]; */
languages?: EditorLanguage[];
/** /**
* Custom languages (outside of the ones shipped with the `monaco-editor`). * Custom languages (outside of the ones shipped with the `monaco-editor`).
*/ */
customLanguages?: IFeatureDefinition[]; customLanguages?: IFeatureDefinition[];
/** /**
* Include only a subset of the editor features. * Include only a subset of the editor features.
* Use e.g. '!contextmenu' to exclude a certain feature. * Use e.g. '!contextmenu' to exclude a certain feature.
*/ */
features?: (EditorFeature | NegatedEditorFeature)[]; features?: (EditorFeature | NegatedEditorFeature)[];
/** /**
* Specify a filename template to use for generated files. * Specify a filename template to use for generated files.
* Use e.g. '[name].worker.[contenthash].js' to include content-based hashes. * Use e.g. '[name].worker.[contenthash].js' to include content-based hashes.
*/ */
filename?: string; filename?: string;
/** /**
* The absolute file system path to the monaco-editor npm module. * The absolute file system path to the monaco-editor npm module.
* Use e.g. `C:\projects\my-project\node-modules\monaco-editor` * Use e.g. `C:\projects\my-project\node-modules\monaco-editor`
*/ */
monacoEditorPath?: string; monacoEditorPath?: string;
/** /**
* Override the public path from which files generated by this plugin will be served. * Override the public path from which files generated by this plugin will be served.
* This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross- * This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-
* origin when using a CDN for other static resources. * origin when using a CDN for other static resources.
* Use e.g. '/' if you want to load your resources from the current origin. * Use e.g. '/' if you want to load your resources from the current origin.
*/ */
publicPath?: string; publicPath?: string;
/** /**
* Specify whether the editor API should be exposed through a global `monaco` object or not. This * Specify whether the editor API should be exposed through a global `monaco` object or not. This
* option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM * option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM
* version of the monaco editor does no longer define a global `monaco` object unless * version of the monaco editor does no longer define a global `monaco` object unless
* `global.MonacoEnvironment = { globalAPI: true }` is set ([change * `global.MonacoEnvironment = { globalAPI: true }` is set ([change
* log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)). * log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
*/ */
globalAPI?: boolean; globalAPI?: boolean;
}
} }
interface IInternalMonacoEditorWebpackPluginOpts { interface IInternalMonacoEditorWebpackPluginOpts {
languages: IFeatureDefinition[]; languages: IFeatureDefinition[];
features: IFeatureDefinition[]; features: IFeatureDefinition[];
@ -158,7 +159,7 @@ interface IInternalMonacoEditorWebpackPluginOpts {
class MonacoEditorWebpackPlugin implements webpack.WebpackPluginInstance { class MonacoEditorWebpackPlugin implements webpack.WebpackPluginInstance {
private readonly options: IInternalMonacoEditorWebpackPluginOpts; private readonly options: IInternalMonacoEditorWebpackPluginOpts;
constructor(options: IMonacoEditorWebpackPluginOpts = {}) { constructor(options: MonacoEditorWebpackPlugin.IMonacoEditorWebpackPluginOpts = {}) {
const monacoEditorPath = options.monacoEditorPath; const monacoEditorPath = options.monacoEditorPath;
const metadata = getEditorMetadata(monacoEditorPath); const metadata = getEditorMetadata(monacoEditorPath);
const languages = resolveDesiredLanguages(metadata, options.languages, options.customLanguages); const languages = resolveDesiredLanguages(metadata, options.languages, options.customLanguages);