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

extract common node modules among sub apps #54

Open
ArtixZ opened this issue Oct 4, 2018 · 7 comments
Open

extract common node modules among sub apps #54

ArtixZ opened this issue Oct 4, 2018 · 7 comments

Comments

@ArtixZ
Copy link

ArtixZ commented Oct 4, 2018

Thanks for creating this awesome example.
After analyzing the bundle file, I found there are a lot of redundancies among sub-apps, because they have many intersection of dependencies.

Is there a way to extract the common dependencies?

@maciej-w
Copy link

The README gives one example of sharing, please see

Multiple Angular Apps

It mentions loading Zone.js once in the portal, I believe you could do the same.

@ArtixZ
Copy link
Author

ArtixZ commented Oct 24, 2018

@maciej-w
I believe this is different. Zone.js is imported here:

https://github.com/me-12/single-spa-portal-example/blob/master/portal/src/portal.js

And it's a global level variable.

But what if I want to extract some common modules( e.g. react, lodash, momentjs ) together into one bundle file. And whenever a sub-app imports react, it imports from the bundle file.

@maciej-w
Copy link

Sorry, it is different...

I found something in the Webpack documentation what might be usefull to you but it would still require one webpack.config for all those apps, which might make sense if you develop your apps separately, then push the ready code into the multiple apps container and build your apps there, then you can deploy them separately afterwards. You'd probably be able to deploy (serve) the common bundle separately...

The process would be:

  • Repo 1: React1

  • Repo 2: React2

  • Repo3: React1 + React2 + webpack.config.js

Result: react1entry + react2entry + commonchunks

https://github.com/webpack/docs/wiki/optimization#multi-page-app

Is this what you're looking for?

@ArtixZ
Copy link
Author

ArtixZ commented Oct 25, 2018

@maciej-w
This really make sense and I believe it should work. Thanks for helping.

But it still is not perfect for my scenario - I'm working on Repo 1 and can't get the source code of Repo 2. I only know we have some large common dependencies, such as React, lodash, etc.

I believe there is something to do with Systemjs, as it is the module importer:

https://github.com/me-12/single-spa-portal-example/blob/master/portal/src/helper.js

But I couldn't figure out how to import the "commonchunks" before doing SystemJS.import(appURL).

Thanks again!

@maciej-w
Copy link

maciej-w commented Nov 5, 2018

Hi @ArtixZ - did you manage to work it out? I found an example which does what you are trying to achieve, the difference is that everything is served from one 'dist' folder, all apps + common chunks. Not sure to be honest how would Webpack find what are your common dependencies so maybe you'd have to specify them yourself. Have a look at this repo

@baetschjunge
Copy link

baetschjunge commented Nov 22, 2018

@ArtixZ I'd also be interested if you'd been able to find any solution on this problem, I'm currently trying to find something to solve this Problem in the Portal example too.

@mbanting
Copy link

mbanting commented Jun 7, 2019

I can't seem to get it to work with Webpack 4's SplitChunksPlugin either.
It nicely extracts the common modules as expected, but single-spa can't mount the app when that happens. Has anyone had any luck with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants