Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research Webpack's module federation API #8397

Closed
4 tasks
jodator opened this issue Nov 2, 2020 · 2 comments
Closed
4 tasks

Research Webpack's module federation API #8397

jodator opened this issue Nov 2, 2020 · 2 comments
Assignees
Labels
domain:dx This issue reports a developer experience problem or possible improvement. domain:extending-builds type:task This issue reports a chore (non-production change) and other types of "todos".

Comments

@jodator
Copy link
Contributor

jodator commented Nov 2, 2020

Provide a description of the task

Research the feasibility of using Wepback's module federation API in order to enable #8395.

Requirements to met:

  • Adding a plugin to a build (might be a new build type).
  • Using imports from base editor plugins (core, engine, utils <EmitterMixin>, ui).
  • Using imports from "common" plugins (widget, clipboard, ... ).
  • Potential to solve CSS double import issue Reseach CSS de-duplication on multiple imports #8400.
@jodator jodator added the type:task This issue reports a chore (non-production change) and other types of "todos". label Nov 2, 2020
@jodator jodator added this to the iteration 38 milestone Nov 2, 2020
@jodator jodator added domain:dx This issue reports a developer experience problem or possible improvement. squad:dx labels Nov 2, 2020
@pomek pomek self-assigned this Nov 10, 2020
@pomek
Copy link
Member

pomek commented Nov 16, 2020

First of all, the documentation for the Module Federation plugin is poor. I needed to search available options via TypeScript types.. But before I started doing anything, I upgraded webpack to the version 5.x, because MF comes with the latest version.

Since the lack of examples in the official documentation, I was also looking for some articles on the Web. I found two that I used as an introduction to the topic:

Unfortunately, I wasn't able to prepare a bundle file that will expose ClassicEditor as the umd build and share our internals. Our dev sample didn't work.

I added the following code as a plugin to the webpack.config.js file in the build-classic/ directory.

new webpack.container.ModuleFederationPlugin( {
	name: 'ClassicEditor',
	filename: 'ckeditor-libs.js',
	shared: [
		'@ckeditor/ckeditor5-core',
		'@ckeditor/ckeditor5-engine',
		'@ckeditor/ckeditor5-ui',
		'@ckeditor/ckeditor5-utils',
		'@ckeditor/ckeditor5-widget'
	],
	library: {
		name: 'ClassicEditor',
		type: 'umd',
		export: 'ClassicEditor'
	}
} );

After commenting out the library option, the build worked again but any additional file (that could contain our internals or things that we want to "share") was not created.

Going through examples I found in the articles above, I noticed that I need to use the import() function to load my entry point (the editor build definition) and pass it through to webpack. After that, additional files were created:

  1. the main bundle that should be imported in the *.html file,
  2. assets with our code (including the ClassicBuild definition),
  3. dependencies from the node_modules/ (mostly lodash).

Unfortunately, everything now is asynchronous, and having the snippet: ClassicEditor.create() below the <script> tag ends with an error:

Uncaught ReferenceError: ClassicEditor is not defined

I tried to mix many different ways to get it working but with no luck. All examples I found were focused on React applications that could load things asynchronously.

I'm thinking that the Module Federation plugin can be good for such things as sharing a single component or load something asynchronously from some external library but in the editor's topic, where things must be done synchronously, it won't work.

@jodator
Copy link
Contributor Author

jodator commented Nov 16, 2020

@pomek Thanks! It looks like we've missed the biggest premise of the Module Federation - to load code from external entry points at run time. This is a killer feature for micro-frontends but it uses an asynchronous-first approach. AFAICS this might not be feasible to use for sharing a code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dx This issue reports a developer experience problem or possible improvement. domain:extending-builds type:task This issue reports a chore (non-production change) and other types of "todos".
Projects
None yet
Development

No branches or pull requests

3 participants