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

UMD build #1136

Closed
privatenumber opened this issue May 7, 2020 · 5 comments
Closed

UMD build #1136

privatenumber opened this issue May 7, 2020 · 5 comments

Comments

@privatenumber
Copy link
Contributor

privatenumber commented May 7, 2020

What problem does this feature solve?

vue-next currently has ESM and global builds for the browser but I noticed it doesn't have a UMD build (whereas v2 does).

While ESM might be the future standard for loading dependencies on the web, it's not ubiquitous yet. And global works, but it pollutes the global scope and requires synchronous loading or a callback. Personally, I default to using SystemJS with the AMD plugin to load dependencies (incl. Vue) in environments where I don't have a bundler (eg. prototyping on a code playground).

UMD and AMD are still very popular module definitions for JS, and I was wondering if there was any consideration for using it as one of the bundle types for v3.

What does the proposed API look like?

UMD

@yyx990803
Copy link
Member

yyx990803 commented May 7, 2020

If you are prototyping, then browser support of ESM isn't really an issue. And SystemJS should work with ESM builds, isn't that what it's all about?

For production there is no point in providing UMD either, since you will be bundling and all major bundlers support ESM today.

Also if you are prototyping with Vue 3 without a bundler, you really should be using https://github.com/vuejs/vite.

@privatenumber
Copy link
Contributor Author

privatenumber commented May 7, 2020

SystemJS doesn't seem to support ESM right now (FR).

I can give you a real example of a production scenario where UMD/AMD would be useful:

We have a large codebase that builds using Webpack with some heavy configuration (server build, mobile build, i18n builds). To help improve build performance and distribution size, we're considering externalizing dependencies with UMD/AMD distributions to a CDN.

With Vue 3, we can't import the ESM bundle (even with SystemJS) because Webpack doesn't seem to support ESM yet.

We can use the global distribution w/ SystemJS, but as I said it's not ideal due to global pollution. To integrate products (Vue apps) from different teams, we are considering the micro-frontends architecture to mount multiple Vue apps (and versions) on one page.

@joeldenning
Copy link
Contributor

joeldenning commented Nov 2, 2020

I help maintain systemjs, and we are discussing this in systemjs/systemjs#2272. One thing to note is that SystemJS can't even load Vue as a global variable, since the vue library creates multiple global variables (Vue, devtoolsFormatters, __VUE__, __VUE_HMR_RUNTIME__), so SystemJS cannot programmatically determine which one to treat as the loaded module.

@cbdyzj
Copy link

cbdyzj commented Mar 8, 2022

Same issue when I writing userscript with requirejs. This is my solution.
https://www.npmjs.com/package/vue-umd

@yuhenabc
Copy link

yuhenabc commented Jul 27, 2023

you can use global Vue + self write vue.amd.js

global Vue:

<!-- development -->
<script src="https://unpkg.com/vue@3.3.4/dist/vue.runtime.global.js"></script>
<!-- production -->
<script src="https://unpkg.com/vue@3.3.4/dist/vue.runtime.global.prod.js"></script>

vue.amd.js:

/* eslint-disable */
define(function () {
  return window.Vue
})

@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants