2 thoughts on “how i can use export default and require (webpack2)

  1. Don’t mix babel es6 module handling with webpacks. webpack allows to mix CommonJs and ES6 modules this way:

    // es6.js
    import something from "./commonjs";
    
    export default "xyz";
    export var abc = "abc";
    // commonjs.js
    var xyz = require("./es6").default;
    var abc = require("./es6").abc;
    
    module.exports = "something";

    Don’t use the add-module-exports plugin.

    PS: exports.a is used instead of exports.default when a es6 module is only imported via es6 imports. webpack mangles the export names.

Comments are closed.