Skip to content

feat: Add support for importing external ES Modules#221

Closed
VLTHellolin wants to merge 3 commits into
lisonge:mainfrom
VLTHellolin:dev/esm-import
Closed

feat: Add support for importing external ES Modules#221
VLTHellolin wants to merge 3 commits into
lisonge:mainfrom
VLTHellolin:dev/esm-import

Conversation

@VLTHellolin
Copy link
Copy Markdown

@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));

  // ...

})();

Comment thread packages/vite-plugin-monkey/src/node/plugins/finalBundle.ts Outdated
@lisonge lisonge closed this Apr 27, 2026
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

2 participants