As of v1.0.15, the default ESM and UMD builds now include markdown-it, tiny-emitter, and diff-match-patch bundled. This means new users no longer need to deal with import maps! Simply use the default builds:
<!-- Just works! No import maps needed -->
<script type="module">
import SquibView from 'https://unpkg.com/squibview/dist/squibview.esm.min.js';
const editor = new SquibView('#editor');
</script>When using the lean builds or running development files in the /dev directory, you might encounter these errors:
Uncaught TypeError: Failed to resolve module specifier "tiny-emitter". Relative references must start with either "/", "./", or "../".Uncaught SyntaxError: The requested module 'diff-match-patch' does not provide an export named 'default'
The lean builds and development files use ES modules directly with import statements like:
import TinyEmitter from 'tiny-emitter';
import DiffMatchPatch from 'diff-match-patch';However, these modules are CommonJS modules, not ES modules, and they don't provide default exports.
For lean builds, use import maps to resolve the module specifiers and esm.sh to convert CommonJS modules to ES modules:
<script type="importmap">
{
"imports": {
"tiny-emitter": "https://esm.sh/tiny-emitter@2.1.0",
"diff-match-patch": "https://esm.sh/diff-match-patch@1.0.5",
"turndown": "https://esm.sh/turndown@7.1.2"
}
}
</script>This ensures that when the source file imports from tiny-emitter or diff-match-patch, it receives a proper ES module with default exports.
The UMD build of SquibView may have issues in browser environments with errors like:
Uncaught ReferenceError: module is not definedCannot read properties of undefined (reading 'version')Uncaught TypeError: e is not a constructor
For UMD build issues, use the wrapper solution in /examples/example_UMD_fixed.html:
<!-- Fix for UMD module issues -->
<script>
// Define module if not already defined (browser environment)
if (typeof module === 'undefined') {
var module = { exports: {} };
}
</script>
<!-- The UMD build -->
<script src="../dist/squibview.umd.min.js"></script>
<script>
// Fix SquibView global if needed
if (typeof SquibView === 'object' && SquibView.__esModule) {
window.SquibView = SquibView.default || SquibView;
}
</script>- Use Default Builds (v1.0.15+): The default ESM and UMD builds now bundle markdown-it, eliminating import map complexity for most users
- Use ESM.sh for Lean Builds: When using lean builds with external dependencies, esm.sh provides proper ES module versions of CommonJS libraries
- Import Maps for Advanced Users: Import maps are now only needed for lean builds or custom dependency management
- Prefer Standalone Build: For testing, the standalone build includes all dependencies and is easier to work with
- Test Multiple Browsers: Some browsers handle ES modules and import maps differently
/examples/example_ESM.html- ES modules example/examples/example_UMD.html- UMD example with fixes/examples/example_UMD_fixed.html- Simplified UMD example with fixes/examples/standalone_umd.html- Standalone UMD example (no external dependencies)