From 577cfae1cf9817de90e94ecd476ed9e9237bf1bf Mon Sep 17 00:00:00 2001 From: guxiang Date: Fri, 14 Aug 2020 04:00:08 +0800 Subject: [PATCH] feat: custom language support and absolute entry fallback --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 38690d65..ff5827d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,11 @@ function resolveMonacoPath(filePath: string): string { try { return require.resolve(path.join('monaco-editor/esm', filePath)); } catch(err) { - return require.resolve(path.join(process.cwd(), 'node_modules/monaco-editor/esm', filePath)); + try { + return require.resolve(path.join(process.cwd(), 'node_modules/monaco-editor/esm', filePath)); + } catch(err){ + return require.resolve(filePath); + } } } @@ -71,6 +75,11 @@ interface IMonacoEditorWebpackPluginOpts { */ languages?: EditorLanguage[]; + /** + * customer languages which feature definition + */ + customLanguages?: IFeatureDefinition[]; + /** * Include only a subset of the editor features. * Use e.g. '!contextmenu' to exclude a certain feature. @@ -107,7 +116,7 @@ class MonacoEditorWebpackPlugin implements webpack.Plugin { const languages = options.languages || Object.keys(languagesById); const features = getFeaturesIds(options.features || []); this.options = { - languages: coalesce(languages.map(id => languagesById[id])), + languages: coalesce(languages.map(id => languagesById[id])).concat(options.customLanguages || []), features: coalesce(features.map(id => featuresById[id])), filename: options.filename || "[name].worker.js", publicPath: options.publicPath || '',