feat: add IIFE and ESM browser builds #1024
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #989.
This change would add two new files to the build output for
@vue/devtools-api:dist/vue-devtools-api.esm-browser.jsdist/vue-devtools-api.global.jsThese 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:@vue/devtools-apiversion 6.@vue/devtools-apiversion 7.In both cases it is using the old v6 API call
setupDevtoolsPlugin.Pinia 2 bundles
@vue/devtools-apiinto 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-apidoesn'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-apiis 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-apito work, and it's tied to the specific dependencies that happen to exist for that particular version.By contrast,
@vue/devtools-apiversion 6 included everything inindex.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:
VueDevToolsApi. Note the capitalTforTools, 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 usingdevtoolsApi. Pinia will need updating to match whatever we use here, though it is trivial to create an alias viavar devtoolsApi = VueDevToolsApi, which is what I used to test these changes.vue-devtools-api, followed by the build type. I've named the IIFE buildglobal, rather than the defaultiife. Some other parts of the Vue ecosystem (including Pinia) use the nameiifeinstead.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
unpkgandjsdelivrentries inpackage.json).Even though these changes only apply to
@vue/devtools-apiversion 8, the resulting builds are usable with Pinia 3. The breaking changes between version 7 and version 8 shouldn't impact these browser builds.