Build React components library with Webpack 4

后端 未结 2 1250
天命终不由人
天命终不由人 2021-02-07 15:19

I\'m currently building a library of React components and bundling it with Webpack 4.

Everything works just fine from building the library\'s bundle to publishing it on

2条回答
  •  醉梦人生
    2021-02-07 15:31

    You're exporting your library as commonjs and trying to import it via import/export syntax. You should change your output to

    output: {
      filename: "index.js",
      path: path.resolve(__dirname, "dist"),
      libraryTarget: "umd",
      library: "my-design-system"
    }
    

    Found a lot of info here: https://webpack.js.org/guides/author-libraries/

提交回复
热议问题