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

feat(build): add an option to use SystemJS #588

Closed
wants to merge 4 commits into from
Closed

feat(build): add an option to use SystemJS #588

wants to merge 4 commits into from

Conversation

hronro
Copy link
Contributor

@hronro hronro commented Jul 20, 2020

fix #554

src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
src/node/config.ts Outdated Show resolved Hide resolved
@hronro
Copy link
Contributor Author

hronro commented Jul 21, 2020

@yyx990803 fixed.

@frehner
Copy link

frehner commented Jul 21, 2020

Interesting!

This would probably require additional work, but do you think you would in the future allow the bare import specifier resolution to be handled by SystemJS' import-map support instead of by Vite?

@hronro
Copy link
Contributor Author

hronro commented Aug 4, 2020

@yyx990803 Is there something else I can do to help this PR merged?

Copy link
Member

@aleclarson aleclarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase to master while you're at it 👍

src/node/config.ts Outdated Show resolved Hide resolved
src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
src/node/build/buildPluginHtml.ts Outdated Show resolved Hide resolved
@hronro
Copy link
Contributor Author

hronro commented Nov 10, 2020

@aleclarson Rebased. Could you check it again?

@aleclarson
Copy link
Member

@yyx990803 You can test yourself with this: https://github.com/aleclarson/repro/tree/vite-588

But I've tested myself, and it's all working ;)

@aleclarson
Copy link
Member

aleclarson commented Nov 10, 2020

Interesting!

This would probably require additional work, but do you think you would in the future allow the bare import specifier resolution to be handled by SystemJS' import-map support instead of by Vite?

@frehner Import maps are working as expected 👍

You just need to define rollupInputOptions.external in your Vite config.

Open to contributions that parse the systemjs-importmap scripts out of index.html, parse the imports map for specifiers, and inject those specifiers into rollupInputOptions.external automatically.

PS: You'll want to put your import-map.json in the public directory, so your index.html has access when in production environment.

@aleclarson
Copy link
Member

aleclarson commented Nov 11, 2020

UMD bundle interop

Some packages (like React) don't have a SystemJS bundle, but they often have a UMD bundle.

The minimal loader (which is embedded in your index.html when useSystemJs: true is defined) does not support UMD bundles, so you need to provide a CDN url for Vite to use the full-featured SystemJS loader instead:

useSystemJs: 'https://unpkg.com/systemjs@6.7.1/dist/system.min.js',

@hronro
Copy link
Contributor Author

hronro commented Dec 1, 2020

May I know is there anything block this PR getting merged?

@aleclarson
Copy link
Member

May I know is there anything block this PR getting merged?

Just waiting on @yyx990803 to approve it. ⏳

@hronro
Copy link
Contributor Author

hronro commented Jan 2, 2021

Hi @yyx990803 and @aleclarson, I just notice v2.0.0-beta.1 has released. I havn't look at the v2 deeply yet, I just wonder if supporting Systemjs in still on the plan of Vite. If it is, I can change my PR to base on v2.

@yyx990803
Copy link
Member

yyx990803 commented Jan 2, 2021

For v2 we will likely provide an official plugin (@vitejs/plugin-legacy) which produces a separate legacy bundle, and transforms the produced HTML to conditionally load the legacy bundle when native dynamic import is not supported.

It's discussed a bit in the docs here: https://vitejs.dev/guide/build.html#browser-compatibility

References:

@yyx990803 yyx990803 closed this Jan 2, 2021
@yyx990803 yyx990803 deleted the branch vitejs:master January 2, 2021 18:17
@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Nov 10, 2022

@yyx990803 SystemJS could be used not only because old browsers don't support dynamic imports, but also because importing hashed chunks is not optimal for long term caching (which could be solved by using import maps, but it's currently supported natively only in chromium-based browsers).

See #6773, sveltejs/kit#4482, rollup/rollup#3407, rollup/rollup#4709

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

Successfully merging this pull request may close these issues.

Support non native ES module build in production via System.js
5 participants