Skip to content

feat: Add support for importing external ES Modules #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

VLTHellolin
Copy link

@VLTHellolin VLTHellolin commented May 2, 2025

Resolve #180.

Pass the modules we want to externalise and their links to externalModules:

monkey({
  // ...
  build: {
    externalModules: {
      react: 'https://esm.sh/react@19.1.0',
      'react-dom': 'https://esm.sh/react-dom@19.1.0',
    },
  },
}),
import React, { useState } from 'react';
import ReactDOM from 'react-dom';

// ...

And the generated code will be as follows:

// ==UserScript==
// @name       esm support test
// @namespace  esm-support-test
// @version    1.0.0
// @author     VLTHellolin
// @match      https://www.google.com/
// ==/UserScript==

(async function () {
  'use strict';

  const require$$0 = await (import('https://esm.sh/react@19.1.0').then(m => m.default));
  const { useState } = await import('https://esm.sh/react@19.1.0');
  const require$$0$1  = await (import('https://esm.sh/react-dom@19.1.0').then(m => m.default));

  // ...

})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support for building with ESM-only libraries
1 participant