Interactivity API: Add build configuration for a standalone package #61681
Interactivity API: Add build configuration for a standalone package #61681michalczaplinski wants to merge 3 commits intotrunkfrom
Conversation
|
Size Change: -140 B (-0.01%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I'll try to give this a proper review at some point, but honestly I'm swamped right now. A quick comment is that I'd stay away from language like "CDN" which is more about how things are served. Instead, I'd talk about "standalone" which I think better indicates the goal here - to have a single file that includes everything necessary and removes the need to bundle/compile. |
That's a very good point, I've updated it. Naming is hard 🙂 |
|
Just a note that in case we go ahead with this, we should apply the similar changes to the |
|
Closing this for now as there hasn't been sufficient interest in a "standalone" package. Happy to re-open if this becomes relevant again. |
|
Sorry, what was this pull request trying to solve? I've been using the package directly from NPM for a while, and it's working well for me. |
|
The idea was to make it easier to use the Interactivity API for people who:
Similar to how Alpine.js has a standalone build. |
|
If they don’t want to use a bundler, they can use an import map: https://stackblitz.com/edit/iapi-no-build <script type="importmap">
{
"imports": {
"@wordpress/interactivity": "https://unpkg.com/@wordpress/interactivity@latest/build-module/index.js",
"preact": "https://unpkg.com/preact@latest/dist/preact.module.js",
"preact/hooks": "https://unpkg.com/preact@latest/hooks/dist/hooks.module.js",
"@preact/signals": "https://unpkg.com/@preact/signals@latest/dist/signals.module.js",
"@preact/signals-core": "https://unpkg.com/@preact/signals-core@latest/dist/signals-core.module.js"
}
}
</script> |
We could add this to the docs 🚀 |
What?
Configure webpack in the Gutenberg repo so that a minified and bundled version of the Interactivity API is also available inside of the built
@wordpress/interactivitynpm package.Why?
A few people asked to use Interactivity API without WordPress and without a build system. they would like to be able to import the package from a CDN and "just use" the Interactivity API.
With this configuration in place, we could then submit
@wordpress/interactivityto cdn.js and have it always pull the latest versionIt is a very common pattern among JS libraries to provide a standalone build. e.g.
petite-vueandalpine.jsboth provide it. We should follow suit. It's not a very important feature in and of itself but having it contributes to the perception that the Interactivity API is easy to use and easy to get started with.How?
Adding a new webpack config and a
buildscript to thepackage.jsonof@wordpress/interactivity. This build script is then run bylernabefore the packages are published (see the"prebuild:packages"in thepackage.jsonat the root of the repo).Testing Instructions
npm run build:packagesand make sure that the Interactivity API buildsbuild-cdnindex-standalone.min.jsfile and on a page that uses the interactivity API and make sure that it works.packages/interactivity/build-cdnfolder is ignored by the editor andgit.