Build dist/prism.js as IIFE for synchronous globalThis.Prism#4087
Open
DmitrySharabin wants to merge 2 commits into
Open
Build dist/prism.js as IIFE for synchronous globalThis.Prism#4087DmitrySharabin wants to merge 2 commits into
DmitrySharabin wants to merge 2 commits into
Conversation
…is.Prism The previous prism.global.js used a dynamic import() to load index.js, which made globalThis.Prism available only asynchronously — breaking backward compatibility with v1 where Prism was available immediately after the <script> tag. Replace prism.global.js with an IIFE build target that bundles auto-start.js (core + autoloader) into a single file. Rollup's `name: 'Prism'` option assigns the default export to `var Prism`, making it synchronously available as a global. Languages are still loaded dynamically by the autoloader. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for dev-prismjs-com ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
ESM plugins import the Prism singleton from global.js. When the IIFE build has already set globalThis.Prism, global.js now reuses that instance instead of creating a second one. This ensures plugins loaded via <script type="module"> register on the same Prism instance as the one exposed by <script src="dist/prism.js">. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cfeb840 to
0a21097
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
prism.global.jsusedimport()to dynamically loadindex.js, makingglobalThis.Prismavailable only asynchronously — breaking backward compatibility with v1 wherePrismwas available immediately after the<script>tagauto-start.js(core + autoloader) into a single self-contained file (~20KB)name: 'Prism'assigns the default export tovar Prism, making it synchronously available as a globalimport()global.jsnow bridges the IIFE and ESM singletons: whenglobalThis.Prismis already a Prism instance (set by the IIFE), ESM plugins reuse it instead of creating a second oneLive demo: https://codepen.io/dmitrysharabin/pen/xbbdXZb
Test plan
dist/prism.jsvia<script>and verifyglobalThis.Prismis defined synchronously in the next<script>block<code class="language-javascript">)import Prism from 'prismjs') and CJS (require('prismjs')) still workwindow.Prism = { manual: true }) is still read correctlyline-numbers,inline-color,show-invisibles) loaded via<script type="module">work alongside the IIFE buildglobalThis.Prismstaysundefined, ESM/CJS return a fresh instance🤖 Generated with Claude Code