How to bundle a library with webpack?

前端 未结 2 1883
夕颜
夕颜 2021-02-03 22:42

I want to create a frontend library. Therefore I want to use webpack. I especially like the css and image loader. However I can only require non-JS files if I am using webpack.

2条回答
  •  北海茫月
    2021-02-03 23:15

    The comment written by @OlegPro is very helpful. I suggest every one to read this article for explanation of how these stuff work

    http://krasimirtsonev.com/blog/article/javascript-library-starter-using-webpack-es6

    You need the following for sure if you want to be able to import the bundle file in your project

      output: {
        path: path.resolve(__dirname, myLibrary),
        filename: 'bundle.js',
        library: "myLibrary",   // Important
        libraryTarget: 'umd',   // Important
        umdNamedDefine: true   // Important
      },
    

提交回复
热议问题