|
|
@ -109,9 +109,17 @@ class MonacoEditorWebpackPlugin implements webpack.Plugin {
|
|
|
|
const { languages, features, filename, publicPath } = this.options;
|
|
|
|
const { languages, features, filename, publicPath } = this.options;
|
|
|
|
const compilationPublicPath = getCompilationPublicPath(compiler);
|
|
|
|
const compilationPublicPath = getCompilationPublicPath(compiler);
|
|
|
|
const modules = [EDITOR_MODULE].concat(languages).concat(features);
|
|
|
|
const modules = [EDITOR_MODULE].concat(languages).concat(features);
|
|
|
|
const workers: ILabeledWorkerDefinition[] = coalesce(modules.map(
|
|
|
|
const workers: ILabeledWorkerDefinition[] = [];
|
|
|
|
({ label, worker }) => worker && (mixin({ label }, worker))
|
|
|
|
modules.forEach((module) => {
|
|
|
|
));
|
|
|
|
if (module.worker) {
|
|
|
|
|
|
|
|
workers.push({
|
|
|
|
|
|
|
|
label: module.label,
|
|
|
|
|
|
|
|
id: module.worker.id,
|
|
|
|
|
|
|
|
entry: module.worker.entry,
|
|
|
|
|
|
|
|
fallback: module.worker.fallback
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
const rules = createLoaderRules(languages, features, workers, filename, publicPath, compilationPublicPath);
|
|
|
|
const rules = createLoaderRules(languages, features, workers, filename, publicPath, compilationPublicPath);
|
|
|
|
const plugins = createPlugins(workers, filename);
|
|
|
|
const plugins = createPlugins(workers, filename);
|
|
|
|
addCompilerRules(compiler, rules);
|
|
|
|
addCompilerRules(compiler, rules);
|
|
|
@ -148,8 +156,8 @@ function createLoaderRules(languages: IFeatureDefinition[], features: IFeatureDe
|
|
|
|
if (!languages.length && !features.length) {
|
|
|
|
if (!languages.length && !features.length) {
|
|
|
|
return [];
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const languagePaths = flatArr(coalesce(languages.map(({ entry }) => entry)));
|
|
|
|
const languagePaths = flatArr(coalesce(languages.map(language => language.entry)));
|
|
|
|
const featurePaths = flatArr(coalesce(features.map(({ entry }) => entry)));
|
|
|
|
const featurePaths = flatArr(coalesce(features.map(feature => feature.entry)));
|
|
|
|
const workerPaths = fromPairs(workers.map(({ label, entry }) => [label, getWorkerFilename(filename, entry)]));
|
|
|
|
const workerPaths = fromPairs(workers.map(({ label, entry }) => [label, getWorkerFilename(filename, entry)]));
|
|
|
|
if (workerPaths['typescript']) {
|
|
|
|
if (workerPaths['typescript']) {
|
|
|
|
// javascript shares the same worker
|
|
|
|
// javascript shares the same worker
|
|
|
@ -208,7 +216,7 @@ function createLoaderRules(languages: IFeatureDefinition[], features: IFeatureDe
|
|
|
|
function createPlugins(workers: ILabeledWorkerDefinition[], filename: string): AddWorkerEntryPointPlugin[] {
|
|
|
|
function createPlugins(workers: ILabeledWorkerDefinition[], filename: string): AddWorkerEntryPointPlugin[] {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
(<AddWorkerEntryPointPlugin[]>[])
|
|
|
|
(<AddWorkerEntryPointPlugin[]>[])
|
|
|
|
.concat(uniqBy(workers, ({ id }) => id).map(({ id, entry }) =>
|
|
|
|
.concat(workers.map(({ id, entry }) =>
|
|
|
|
new AddWorkerEntryPointPlugin({
|
|
|
|
new AddWorkerEntryPointPlugin({
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
entry: resolveMonacoPath(entry),
|
|
|
|
entry: resolveMonacoPath(entry),
|
|
|
@ -234,26 +242,6 @@ function fromPairs<T>(values: [string, T][]): { [key: string]: T; } {
|
|
|
|
return values.reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), <{ [key: string]: T; }>{});
|
|
|
|
return values.reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), <{ [key: string]: T; }>{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uniqBy<T>(items: T[], iteratee: (item: T) => string): T[] {
|
|
|
|
|
|
|
|
const keys: { [key: string]: boolean; } = {};
|
|
|
|
|
|
|
|
return items.reduce((acc, item) => {
|
|
|
|
|
|
|
|
const key = iteratee(item);
|
|
|
|
|
|
|
|
if (key in keys) { return acc; }
|
|
|
|
|
|
|
|
keys[key] = true;
|
|
|
|
|
|
|
|
acc.push(item);
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
|
|
|
|
}, <T[]>[]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mixin<DEST, SRC>(dest: DEST, src: SRC): DEST & SRC {
|
|
|
|
|
|
|
|
for (let prop in src) {
|
|
|
|
|
|
|
|
if (Object.hasOwnProperty.call(src, prop)) {
|
|
|
|
|
|
|
|
(<any>dest)[prop] = src[prop];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return <any>dest;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
|
|
|
|
function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
|
|
|
|
return <T[]>array.filter(Boolean);
|
|
|
|
return <T[]>array.filter(Boolean);
|
|
|
|
}
|
|
|
|
}
|
|
|
|