From 9c1ad157a45f10d03fcc17f94ef0e82a66b5313e Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 6 Dec 2023 14:38:42 +0100 Subject: [PATCH] feat: export one bundle with and one without external dependencies in `vanilla-jsoneditor` (#353) BREAKING CHANGE: When using `vanilla-jsoneditor` directly in the browser, you now have to `import { JSONEditor } from 'vanilla-jsoneditor/standalone.js'` instead of `import { JSONEditor } from 'vanilla-jsoneditor'`. For projects with a build setup (React, Vue, Angular) it should be a drop-in replacement. --- README-VANILLA.md | 30 ++++++++++++---- README.md | 30 +++++++++++----- examples/browser/basic_usage.html | 2 +- examples/browser/custom_theme_color.html | 2 +- examples/browser/json_schema_validation.html | 2 +- examples/browser/toggle_options.html | 2 +- package.json | 5 +-- rollup.config.vanilla-bundle.js | 18 ++++++++++ ...dle.js => rollup.config.vanilla-library.js | 2 ++ ...types.js => rollup.config.vanilla-types.js | 0 .../components/modes/textmode/TextMode.svelte | 5 ++- tools/createVanillaPackageJson.js | 35 ++++--------------- tools/develop-vanilla.html | 2 +- tools/getExternalDependencies.js | 11 ++++++ 14 files changed, 94 insertions(+), 52 deletions(-) create mode 100644 rollup.config.vanilla-bundle.js rename rollup.config.bundle.js => rollup.config.vanilla-library.js (91%) rename rollup.config.bundle-types.js => rollup.config.vanilla-types.js (100%) create mode 100644 tools/getExternalDependencies.js diff --git a/README-VANILLA.md b/README-VANILLA.md index edcf6b24..424d5f71 100644 --- a/README-VANILLA.md +++ b/README-VANILLA.md @@ -30,7 +30,25 @@ Install using npm: npm install vanilla-jsoneditor ``` -Remark: for usage in a Svelte project, install `svelte-jsoneditor` instead. +Remark: for usage in a Svelte project, install and use `svelte-jsoneditor` instead of `vanilla-jsoneditor`. + +## Use + +If you have a setup for your project with a bundler (like Vite, Rollup, or Webpack), it is best to use the default ES import: + +```ts +// for use in a React, Vue, or Angular project +import { JSONEditor } from 'vanilla-jsoneditor' +``` + +If you want to use the library straight in the browser, use the provided standalone ES bundle: + +```ts +// for use directly in the browser +import { JSONEditor } from 'vanilla-jsoneditor/standalone.js' +``` + +The standalone bundle contains all dependencies of `vanilla-jsoneditor`, for example `lodash-es` and `Ajv`. If you use some of these dependencies in your project too, it means that they will be bundled twice in your web application, leading to a needlessly large application size. In general, it is preferable to use the default `import { JSONEditor } from 'vanilla-jsoneditor'` so dependencies can be reused. ## Use (Browser example loading the ES module): @@ -44,7 +62,7 @@ Remark: for usage in a Svelte project, install `svelte-jsoneditor` instead.