PrismJS / PrismJS/prism

Should Prism-core be default exported?

Open
#2,155 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

Motivation

Now we cannot use Prism via ES Modules, because Prism is exported to only module.exports or global in prism-core.js. This restricts library usage in the following ways.

  • import Prism from 'https://example.com/path/to/prism.js';
  • import('https://example.com/path/to/prism.js').then(Prism => ..);
  • <script type="module" src="https://example.com/path/to/prism.js"></script>

Description

  1. How about separating prism-core.js into the following files?
    • prism-core.js: defines Prism object and export default it. it does not do the browser-specific and Node.js-specific process. The filename can be prism.mjs.
    • browser.js: imports prism.js and do the browser-specific process such as highlighting automatically on DCL.
    • cjs.js: import prism.js and export it as CommonJS. but this file might be deprecated because of CommonJS-obsoletion in the future.
  2. package.json fields will be:
    • "main": "prism.js",
    • "module": "prism.js",
  3. Entry points will be:
    • https://unpkg.com/prismjs/prism.js for ES Modules
    • https://unpkg.com/prismjs/browser.js for Browsers
    • https://unpkg.com/prismjs/cjs.js for traditional Node.js

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with prism-core.js at the export logic around lines 614–621, then inspect package.json and the existing entry points. Compare how browser-specific and Node.js-specific behavior is currently handled with the proposed prism.js, browser.js, and cjs.js split. Done means ES module, browser, and CommonJS entry points work as described without breaking existing usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.