mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Fixes #21
This commit is contained in:
parent
98d97d8541
commit
ebe8c27add
1 changed files with 23 additions and 14 deletions
37
index.js
37
index.js
|
|
@ -37,10 +37,10 @@ function resolveMonacoPath(filePath) {
|
||||||
|
|
||||||
const languagesById = fromPairs(
|
const languagesById = fromPairs(
|
||||||
flatMap(toPairs(LANGUAGES), ([id, language]) =>
|
flatMap(toPairs(LANGUAGES), ([id, language]) =>
|
||||||
[id, ...(language.alias || [])].map((label) => [label, { label, ...language }])
|
[id].concat(language.alias || []).map((label) => [label, mixin({ label }, language)])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const featuresById = mapValues(FEATURES, (feature, key) => ({ label: key, ...feature }))
|
const featuresById = mapValues(FEATURES, (feature, key) => mixin({ label: key }, feature))
|
||||||
|
|
||||||
class MonacoWebpackPlugin {
|
class MonacoWebpackPlugin {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
|
|
@ -57,9 +57,9 @@ class MonacoWebpackPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const { languages, features, output } = this.options;
|
const { languages, features, output } = this.options;
|
||||||
const publicPath = getPublicPath(compiler);
|
const publicPath = getPublicPath(compiler);
|
||||||
const modules = [EDITOR_MODULE, ...languages, ...features];
|
const modules = [EDITOR_MODULE].concat(languages).concat(features);
|
||||||
const workers = modules.map(
|
const workers = modules.map(
|
||||||
({ label, alias, worker }) => worker && ({ label, alias, ...worker })
|
({ label, alias, worker }) => worker && (mixin({ label, alias }, worker))
|
||||||
).filter(Boolean);
|
).filter(Boolean);
|
||||||
const rules = createLoaderRules(languages, features, workers, output, publicPath);
|
const rules = createLoaderRules(languages, features, workers, output, publicPath);
|
||||||
const plugins = createPlugins(workers, output);
|
const plugins = createPlugins(workers, output);
|
||||||
|
|
@ -71,8 +71,7 @@ class MonacoWebpackPlugin {
|
||||||
function addCompilerRules(compiler, rules) {
|
function addCompilerRules(compiler, rules) {
|
||||||
const compilerOptions = compiler.options;
|
const compilerOptions = compiler.options;
|
||||||
const moduleOptions = compilerOptions.module || (compilerOptions.module = {});
|
const moduleOptions = compilerOptions.module || (compilerOptions.module = {});
|
||||||
const existingRules = moduleOptions.rules || (moduleOptions.rules = []);
|
moduleOptions.rules = (moduleOptions.rules || []).concat(rules);
|
||||||
existingRules.push(...rules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCompilerPlugins(compiler, plugins) {
|
function addCompilerPlugins(compiler, plugins) {
|
||||||
|
|
@ -124,11 +123,12 @@ function createPlugins(workers, outputPath) {
|
||||||
const workerFallbacks = workers.reduce((acc, { id, fallback }) => (fallback ? Object.assign(acc, {
|
const workerFallbacks = workers.reduce((acc, { id, fallback }) => (fallback ? Object.assign(acc, {
|
||||||
[id]: resolveMonacoPath(fallback)
|
[id]: resolveMonacoPath(fallback)
|
||||||
}) : acc), {});
|
}) : acc), {});
|
||||||
return [
|
return (
|
||||||
...Object.keys(IGNORED_IMPORTS).map((id) =>
|
[]
|
||||||
|
.concat(Object.keys(IGNORED_IMPORTS).map((id) =>
|
||||||
createIgnoreImportsPlugin(id, IGNORED_IMPORTS[id])
|
createIgnoreImportsPlugin(id, IGNORED_IMPORTS[id])
|
||||||
),
|
))
|
||||||
...uniqBy(workers, ({ id }) => id).map(({ id, entry, output }) =>
|
.concat(uniqBy(workers, ({ id }) => id).map(({ id, entry, output }) =>
|
||||||
new AddWorkerEntryPointPlugin({
|
new AddWorkerEntryPointPlugin({
|
||||||
id,
|
id,
|
||||||
entry: resolveMonacoPath(entry),
|
entry: resolveMonacoPath(entry),
|
||||||
|
|
@ -138,9 +138,9 @@ function createPlugins(workers, outputPath) {
|
||||||
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
),
|
))
|
||||||
...(workerFallbacks ? [createContextPlugin(WORKER_LOADER_PATH, workerFallbacks)] : []),
|
.concat(workerFallbacks ? [createContextPlugin(WORKER_LOADER_PATH, workerFallbacks)] : [])
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContextPlugin(filePath, contextPaths) {
|
function createContextPlugin(filePath, contextPaths) {
|
||||||
|
|
@ -159,7 +159,7 @@ function createIgnoreImportsPlugin(targetPath, ignoredModules) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function flatMap(items, iteratee) {
|
function flatMap(items, iteratee) {
|
||||||
return items.map(iteratee).reduce((acc, item) => [...acc, ...item], []);
|
return items.map(iteratee).reduce((acc, item) => [].concat(acc).concat(item), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPairs(object) {
|
function toPairs(object) {
|
||||||
|
|
@ -188,4 +188,13 @@ function uniqBy(items, iteratee) {
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mixin(dest, src) {
|
||||||
|
for (let prop in src) {
|
||||||
|
if (Object.hasOwnProperty.call(src, prop)) {
|
||||||
|
dest[prop] = src[prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = MonacoWebpackPlugin;
|
module.exports = MonacoWebpackPlugin;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue