question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rewrite prism in esm

See original GitHub issue

Motivation Many modules are supporting esm now, it is better for bundlers to do tree-shaking and do care node.js and browser environment with separated bundle.js.

Description Bundlers like rollup or webpack want to see esm modules and they do tree-shaking for smaller size. Currently you’re using cjs and supporting both node.js and browser by hand (instead of umd). This is bad bacause it exports some global variables like _self in browser and you won’t be able to use it in the native esm way because imports order is not guaranteed. See vite#1438 since vite depends on native esm in development mode. This solution is also wrong.

As a result, your package.json should look like this:

{
    // node's require and import, to override it, see "exports"
    "main": "dist/index.js",
    // https://nodejs.org/api/packages.html#packages_conditional_exports
    "exports": {
        "node": {
            "import": "./src/index.mjs",
            "require": "./dist/index.js"
        },
        "default": "./src/index.browser.mjs"
    },
    // front-end bundler read this (like vite or webpack)
    "module": "src/index.browser.mjs"
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
RunDevelopmentcommented, Feb 8, 2022

It’s planned for v2, so yes.

2reactions
RunDevelopmentcommented, Sep 9, 2022

Implemented in v2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Rewrite prism in esm - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
rehype-prism | Yarn - Package Manager
The unified plugin used to highlight code block in html with Prism. Usage.
Read more >
Chapter 2 - The PRISM framework
The PRISM system specifications were produced by the PRISM System ... rewrite of the Met Office very complete suite of tools for ESMs...
Read more >
The case for Weak Dependencies in JS - Lea Verou
One issue with ESM (and other module systems) is that you can't have optional dependencies. With globals, you could check if a global...
Read more >
August 2015 – svenweller - WordPress.com
MYSCHEMA, MV_CLI_PROGRAMME_USER, REWRITE_FULL_TEXT_MATCH, F, ESM.PERSON, 216, 2099, mv references a remote table or view in the FROM list ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found