Skip to content

Comments

feat: add IIFE and ESM browser builds#1024

Merged
webfansplz merged 1 commit intovuejs:mainfrom
skirtles-code:browser-builds
Feb 4, 2026
Merged

feat: add IIFE and ESM browser builds#1024
webfansplz merged 1 commit intovuejs:mainfrom
skirtles-code:browser-builds

Conversation

@skirtles-code
Copy link
Contributor

Closes #989.

This change would add two new files to the build output for @vue/devtools-api:

  • dist/vue-devtools-api.esm-browser.js
  • dist/vue-devtools-api.global.js

These are ESM and IIFE builds respectively, intended to be used directly in the browser without using a bundler, e.g. via a CDN.

Background

Pinia uses @vue/devtools-api. Specifically:

  • Pinia 2 uses @vue/devtools-api version 6.
  • Pinia 3 uses @vue/devtools-api version 7.

In both cases it is using the old v6 API call setupDevtoolsPlugin.

Pinia 2 bundles @vue/devtools-api into its IIFE build. But this changed in version 3 and it is now expected to be included separately. This is a problem because @vue/devtools-api doesn't currently provide a global/IIFE build:

This is the motivation behind adding an IIFE build for @vue/devtools-api.

Pinia also provides pinia.esm-browser.js. This is intended to be used directly in a browser using an import map. In this build @vue/devtools-api is kept external.

In theory this can use the existing ESM build of @vue/devtools-api, but that's more difficult than it sounds because of all the other dependencies that need to be included. To get it to work you need something like this:

{
  "vue": "https://play.vuejs.org/vue.runtime.esm-browser.js",
  "@vue/devtools-api": "https://unpkg.com/@vue/devtools-api@8/dist/index.js",
  "@vue/devtools-kit": "https://unpkg.com/@vue/devtools-kit@8/dist/index.js",
  "@vue/devtools-shared": "https://unpkg.com/@vue/devtools-shared@8/dist/index.js",
  "birpc": "https://unpkg.com/birpc@4/dist/index.mjs",
  "hookable": "https://unpkg.com/hookable@6/dist/index.mjs",
  "perfect-debounce": "https://unpkg.com/perfect-debounce@2/dist/index.mjs",
  "pinia": "https://unpkg.com/pinia@3/dist/pinia.esm-browser.js"
}

This does work, but it needs 6 entries to get @vue/devtools-api to work, and it's tied to the specific dependencies that happen to exist for that particular version.

By contrast, @vue/devtools-api version 6 included everything in index.js, so only one file was required to use it with an import map.

Of course, Pinia is not the only library using @vue/devtools-api. Hopefully other libraries will benefit from these extra builds too. Several libraries, including Vue Router, are currently using version 6 and hopefully these extra builds will make it easier to migrate to version 8.

Names

I've made various decisions regarding naming that are worth noting:

  • For the global variable, I've called it VueDevToolsApi. Note the capital T for Tools, which seems to be the convention that's being used elsewhere in the project. Also note that this does not match what's expected by Pinia, which is using devtoolsApi. Pinia will need updating to match whatever we use here, though it is trivial to create an alias via var devtoolsApi = VueDevToolsApi, which is what I used to test these changes.
  • For the filenames, I've followed the conventions used by Vue, beginning with vue-devtools-api, followed by the build type. I've named the IIFE build global, rather than the default iife. Some other parts of the Vue ecosystem (including Pinia) use the name iife instead.

Alternatives

These two builds are independent, though the changes required are similar. If needs be I could split this into two PRs, allowing for one to be merged without the other.

An alternative to adding a separate ESM browser build would be to replace the existing ESM build.

Testing

I've only tested these builds with a simple Vue/Pinia application and the Chrome browser extension. That did seem to work correctly, with data from Pinia visible and editable from the extension.

Some aspects won't be fully testable until these changes are deployed to CDNs (e.g. the unpkg and jsdelivr entries in package.json).

Even though these changes only apply to @vue/devtools-api version 8, the resulting builds are usable with Pinia 3. The breaking changes between version 7 and version 8 shouldn't impact these browser builds.

@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for vue-devtools-docs canceled.

Name Link
🔨 Latest commit 80a8bfe
🔍 Latest deploy log https://app.netlify.com/projects/vue-devtools-docs/deploys/695e8249f8a17000088c3868

@posva
Copy link
Member

posva commented Jan 30, 2026

I wonder if we should ship an iife or rather improve docs around how to use vue devtools with esm builds. Nowadays, one should prefer using the esm version over the iife, which can support devtools. And in 99% of cases one should use a bundler which just works

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 4, 2026

Open in StackBlitz

@vue/devtools-applet

npm i https://pkg.pr.new/@vue/devtools-applet@1024

@vue/devtools-core

npm i https://pkg.pr.new/@vue/devtools-core@1024

@vue/devtools

npm i https://pkg.pr.new/@vue/devtools@1024

@vue/devtools-api

npm i https://pkg.pr.new/@vue/devtools-api@1024

@vue/devtools-kit

npm i https://pkg.pr.new/@vue/devtools-kit@1024

vite-plugin-vue-devtools

npm i https://pkg.pr.new/vite-plugin-vue-devtools@1024

commit: 80a8bfe

@webfansplz webfansplz merged commit 62fe5ba into vuejs:main Feb 4, 2026
8 checks passed
@webfansplz
Copy link
Member

I wonder if we should ship an iife or rather improve docs around how to use vue devtools with esm builds. Nowadays, one should prefer using the esm version over the iife, which can support devtools. And in 99% of cases one should use a bundler which just works

We are releasing this in v8 to ensure compatibility for IIFE users, with plans to deprecate it in the upcoming major version.

@posva
Copy link
Member

posva commented Feb 4, 2026

Noted, I will update the builds in vue router and pinia. I already removed the devtools from the iifee builds to not break

This was referenced Feb 4, 2026
This was referenced Feb 17, 2026
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.

[Feature request] Expose devtoolsApi to browser

3 participants