How to use blueimp-file-upload with webpack?

前端 未结 9 1952
无人共我
无人共我 2021-02-05 08:46

I\'m using blueimp-file-upload in my website, and I\'m using webpack to organize my js code.

I installed blueimp-file-upload and jquery.ui.widget from NPM



        
9条回答
  •  死守一世寂寞
    2021-02-05 08:56

    If you're working with images:

    Webpack was complaining about some modules that weren't in the blueimp-file-upload package. Here is the way I got this working:

    Install missing dependencies:

    npm i -S blueimp-load-image
    npm i -S blueimp-canvas-to-blob
    

    Configure Webpack:

    config.resolve = {
       extensions: ['', '.js'],
       alias: {
          'load-image': 'blueimp-load-image/js/load-image.js',
          'load-image-meta': 'blueimp-load-image/js/load-image-meta.js',
          'load-image-exif': 'blueimp-load-image/js/load-image-exif.js',
          'canvas-to-blob': 'blueimp-canvas-to-blob/js/canvas-to-blob.js',
          'jquery-ui/widget': 'blueimp-file-upload/js/vendor/jquery.ui.widget.js'
       }
    };
    

    Include scripts in your app:

    import "blueimp-file-upload/js/vendor/jquery.ui.widget.js";
    import "blueimp-file-upload/js/jquery.iframe-transport.js";
    import "blueimp-file-upload/js/jquery.fileupload.js";
    import "blueimp-file-upload/js/jquery.fileupload-image.js";
    

提交回复
热议问题