Fix worker output path in loader rules

This commit is contained in:
Tim Kendrick 2018-06-12 08:52:45 +01:00
parent 5f84834ffa
commit c20f6dd6aa
2 changed files with 5 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# Monaco Editor Webpack Loader Plugin # Monaco Editor Webpack Loader Plugin
A plugin to simplify loading the [Monaco Editor](https://github.com/Microsoft/monaco-editor) with [webpack](https://webpack.js.org/) contributed by [Tim Kendrik](https://github.com/timkendrick). A plugin to simplify loading the [Monaco Editor](https://github.com/Microsoft/monaco-editor) with [webpack](https://webpack.js.org/).
## Installing ## Installing
```sh ```sh
@ -38,7 +38,7 @@ monaco.editor.create(document.getElementById('container'), {
Options can be passed in to `MonacoWebpackPlugin`. They can be used to generate a smaller editor bundle by selecting only certain languages or only certain editor features: Options can be passed in to `MonacoWebpackPlugin`. They can be used to generate a smaller editor bundle by selecting only certain languages or only certain editor features:
* `output` (`string`) - append a certain string to all generated files. * `output` (`string`) - custom output path for worker scripts, relative to the main webpack `output.path`.
* default value: `''`. * default value: `''`.
* `languages` (`string[]`) - include only a subset of the languages supported. * `languages` (`string[]`) - include only a subset of the languages supported.
* default value: `['bat', 'coffee', 'cpp', 'csharp', 'csp', 'css', 'dockerfile', 'fsharp', 'go', 'handlebars', 'html', 'ini', 'java', 'json', 'less', 'lua', 'markdown', 'msdax', 'mysql', 'objective', 'pgsql', 'php', 'postiats', 'powershell', 'pug', 'python', 'r', 'razor', 'redis', 'redshift', 'ruby', 'sb', 'scss', 'solidity', 'sql', 'swift', 'typescript', 'vb', 'xml', 'yaml']`. * default value: `['bat', 'coffee', 'cpp', 'csharp', 'csp', 'css', 'dockerfile', 'fsharp', 'go', 'handlebars', 'html', 'ini', 'java', 'json', 'less', 'lua', 'markdown', 'msdax', 'mysql', 'objective', 'pgsql', 'php', 'postiats', 'powershell', 'pug', 'python', 'r', 'razor', 'redis', 'redshift', 'ruby', 'sb', 'scss', 'solidity', 'sql', 'swift', 'typescript', 'vb', 'xml', 'yaml']`.

View file

@ -61,7 +61,7 @@ class MonacoWebpackPlugin {
const workers = modules.map( const workers = modules.map(
({ label, alias, worker }) => worker && ({ label, alias, ...worker }) ({ label, alias, worker }) => worker && ({ label, alias, ...worker })
).filter(Boolean); ).filter(Boolean);
const rules = createLoaderRules(languages, features, workers, publicPath); const rules = createLoaderRules(languages, features, workers, output, publicPath);
const plugins = createPlugins(workers, output); const plugins = createPlugins(workers, output);
addCompilerRules(compiler, rules); addCompilerRules(compiler, rules);
addCompilerPlugins(compiler, plugins); addCompilerPlugins(compiler, plugins);
@ -83,11 +83,11 @@ function getPublicPath(compiler) {
return compiler.options.output && compiler.options.output.publicPath || ''; return compiler.options.output && compiler.options.output.publicPath || '';
} }
function createLoaderRules(languages, features, workers, publicPath) { function createLoaderRules(languages, features, workers, outputPath, publicPath) {
if (!languages.length && !features.length) { return []; } if (!languages.length && !features.length) { return []; }
const languagePaths = languages.map(({ entry }) => entry).filter(Boolean); const languagePaths = languages.map(({ entry }) => entry).filter(Boolean);
const featurePaths = features.map(({ entry }) => entry).filter(Boolean); const featurePaths = features.map(({ entry }) => entry).filter(Boolean);
const workerPaths = fromPairs(workers.map(({ label, output }) => [label, output])); const workerPaths = fromPairs(workers.map(({ label, output }) => [label, path.join(outputPath, output)]));
const globals = { const globals = {
'MonacoEnvironment': `(function (paths) { 'MonacoEnvironment': `(function (paths) {