webpack imported module is not a constructor

后端 未结 2 1998
情书的邮戳
情书的邮戳 2021-02-06 23:42

I created a small JS module which I intend to make an npm package, but for now is just on GitHub. This module is written in ES6 and SCSS, and is thus relying on webpack and babe

2条回答
  •  渐次进展
    2021-02-07 00:32

    It is not working because it is missing libraryTarget and library properties. By doing that webpack know which format of module you would like to create, i.e: commonjs (module.exports) or es (export).

    I would do something like:

    ...
      output: {
        path: path.join(__dirname, 'dist'),
        filename: path.join('[name]', 'index.js'),
        library: "my-library",
        libraryTarget: "umd" // exposes and know when to use module.exports or exports.
      },
    ...
    

提交回复
热议问题