Rewrite external imports to use esm.sh

1 day ago 3
ARTICLE AD BOX

You can write a custom plugin in your rollup config to rewrite the import and set it as external, for eg:

plugins: [ rewriteImportsPlugin({ 'react-dom/client': 'https://esm.sh/[email protected]/client', }) ], function rewriteImportsPlugin(mappings) { return { name: 'rewrite-imports', resolveId(source) { if (mappings[source]) { return { id: mappings[source], external: true }; } return null; } }; }
Read Entire Article