testingwebpackes6-modulesesmodules

Can webpack generate a module with exports?


I was able to create a webpack config to bundle few modules. The generated bundle looks as follows:

/* harmony default export */ const subscriptions = ({
... // my stuff
/******/ })()
;

I'd like to test the generated bundle so i need to have some exports instead of self-invoking function to import it in the test and make sure everything is aliased as expected (so i have correct resolve.alias webpack section in my config), smth similar to the following:

export const subscriptions = ...

Is it possible to instruct webpack to generate it as a module?


Solution

  • Did it with the following webpack config:

        ...
        output: {
          ...
          library: {type: "module"}
        },
        experiments: {
          outputModule: true
        },
        ...