Code Monkey home page Code Monkey logo

mf.monaco.sample's Introduction

Module Federation: Monaco Editor (Sample)

A stripped back demonstration repo of exporting the Monaco code editor via Module Federation.

 

Getting Started

From the root run yarn to get the "workspace" installed.

yarn install

 

Structure

pkg/
  - host     Consumes the exposed monoaco <Editor> (port 3000)
  - monaco   Exposes an <Editor> (port 3001)

Monaco

The pkg/monaco/ module is based on the sample webpack configuration found in browser-esm-webpack-typescript example in the monaco-editor-samples repo.

When run standalone (no module-federation) is works fine as per the sample, notably loading it's workers locally:

cd pkg/monaco/
yarn start

http://localhost:3001/

working

Note the /src/MonacoEnvironment.ts file which provides the editor with a global function used to generate URLs to the web-workers to load.

Host

To run both the host and monaco modules together, from the project root:

yarn start

Then open http://localhost:3000

The MonacoEnvironment.ts contains a hack that when running as a federated import it returns the URL to the worker pointing back to it's origin url, eg:

 

MonacoEnvironment.getWorkerUrl => http://localhost:3001/ts.worker.js

 

Problem

problem

When the http://localhost:3001/ts.worker.js file is loaded remotely it causes an error

Unexpected usage
    at EditorSimpleWorker.loadForeignModule

This appears to be an error internal to Monaco thrown within it's web-worker load sequence. So something is different when the editor loads locally on it's own dev-server/entry-point vs when that code is imported via Module Federation.

 

Fix Ideas

  • Package the workers differently (targetted as webworker)? *
  • Some other MF trick(??)

 

 

mf.monaco.sample's People

Contributors

philcockfield avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.