首页 > Web开发 > 详细

[Webpack 2] Import a non-ES6 module with Webpack

时间:2016-06-25 06:05:48      阅读:240      评论:0      收藏:0      [点我收藏+]

When you have a dependency that does not export itself properly, you can use the exports-loader to force it to export the pieces of the file that you need.

 

Install:

npm i -D exports-loader

 

Add exports-loader to the module you want:

 module: {
      loaders: [
       ...
        {
          test: require.resolve(./src/js/non_node_modules/left-pad),
          loaders: [
            exports?leftPad,
          ],
        }
      ],

 

There is no problem, the module still exists on ‘window‘ object, we want it be es6 module which not exists on ‘window‘ object.

Install:

npm i -D imports-loader

Add imports-loader the the module:

    module: {
      loaders: [
        ...
        {
          test: require.resolve(./src/js/non_node_modules/left-pad),
          loaders: [
            imports?window=>{},
            exports?leftPad,
          ],
        }
      ],
    },

Here it sets ‘windows‘ object to empty object to clean the left-pad module.

 

[Webpack 2] Import a non-ES6 module with Webpack

原文:http://www.cnblogs.com/Answer1215/p/5615671.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!