You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AMD and I think CommonJS also are transformed correctly, e.g. AMD compiles to:
return new Promise(function (resolve, reject) { require(['some-external-lib'], function (m) { resolve(_interopNamespace(m)); }, reject) });
Feature Proposal
In UMD builds the dynamic import should be replaced by a UMD factory. I wrote a plugin to do this for me for now, but I think something like this should be builtin:
/** * Replaces named, dynamic imports with an UMD factory. Absolute and relative imports are ignored. * * Requires an environment that supports `Promise`. */functionpluginDynamicImports(options={}){return{name: 'dynamic-imports',transform(code,filename){// TODO: warn/error if globalName is not specified in UMD environment.// TODO: global is hardcoded to window, which is wrong.consttransformedCode=code.replace(/import\(['"`](?![\.\/])(.*?)['"`]\)/gi,(match,request)=>{constglobalName=options.globals[request]return`new Promise(function (resolve, reject) { (function (global) { typeof exports === 'object' && typeof module !== 'undefined' ? resolve(require("${request}")) : typeof define === 'function' && define.amd ? require(["${request}"], resolve, reject) : (global = global || self, resolve(global["${globalName}"])); }(window)); })`})returntransformedCode},}}
The text was updated successfully, but these errors were encountered:
@dutchigor I haven't used this in months, but the code I posted above is the plugin: function pluginDynamicImports .... You should be able to add it to your rollup.config.js like so:
Feature Use Case
Dynamic imports should work in UMD environments as well:
AMD and I think CommonJS also are transformed correctly, e.g. AMD compiles to:
Feature Proposal
In UMD builds the dynamic import should be replaced by a UMD factory. I wrote a plugin to do this for me for now, but I think something like this should be builtin:
The text was updated successfully, but these errors were encountered: