Conditional export in ES2015
问题 Let's say you're developing a polyfill and don't want to shim a class if it already exists in the browser. How can this be done in ES6? The following is not valid because exports is not a statement: if (typeof Foo === 'undefined') { export class Foo { ... } } If the condition above evaluates to false , the importing script should get the browser built-in. 回答1: export should be static. For conditional exports CommonJS modules and exports can be used. It should be handled with ES6 modules this