Loading the library#
Choose the way that fits your project. Load the library once per page: two copies would each keep their own forms, and getForm of one copy doesn't see the forms of the other.
With a bundler#
Vite, webpack, Rollup, esbuild and the other bundlers resolve the package installed with a package manager.
1 | |
1 | |
import loads the ES module build and require the UMD build: use one of the two in the whole app, since mixing them loads the library twice.
From a CDN#
@4 follows the 4.x releases without jumping to a future major version, which could break your configuration. To freeze a release, write the exact version (e.g. @4.0.0). Avoid @latest.
Script tag#
The script defines the global variable DynamicForms.
1 2 3 4 | |
https://unpkg.com/@simomosi/dynamic-forms@4 serves the same file.
Script tag with Subresource Integrity#
With Subresource Integrity the browser runs the script only if it is exactly the published file. It needs an exact version and the full file path:
1 2 3 4 | |
For another version, take the hash from the version's page on jsDelivr, or compute it:
1 | |
ES module#
1 2 3 | |
esm.sh also sends the TypeScript types (useful with Deno). https://cdn.jsdelivr.net/npm/@simomosi/dynamic-forms@4/+esm works too.
Without a bundler: import map#
In a plain html page, import ... from '@simomosi/dynamic-forms' works only with an import map, which tells the browser where the package is. Without it (or a bundler, or a dev server like Vite's) the browser throws a TypeError.
1 2 3 4 5 6 | |
Self-hosting#
To serve the library from your own site, copy one of these files from the npm package (node_modules/@simomosi/dynamic-forms/dist/):
dynamic-forms.js: the ES module, for<script type="module">and import maps;dynamic-forms.umd.js: the UMD build, for a<script>tag (definesDynamicForms).
1 2 3 4 5 | |
Build scripts and copy plugins can find the files with require.resolve('@simomosi/dynamic-forms/dist/dynamic-forms.umd.js') or import.meta.resolve('@simomosi/dynamic-forms/dist/dynamic-forms.js').