[Webpack 2] Import a non-ES6 module with Webpack
2016-06-25 01:22
706 查看
When you have a dependency that does not export itself properly, you can use the
Install:
Add exports-loader to the module you want:
There is no problem, the module still exists on 'window' object, we want it be es6 module which not exists on 'window' object.
Install:
Add imports-loader the the module:
Here it sets 'windows' object to empty object to clean the left-pad module.
exports-loaderto 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 configuration
- [Webpack 2] Grouping vendor files with the Webpack CommonsChunkPlugin
- [Webpack 2] Hashing with Webpack for long term caching
- [Webpack 2] Polyfill Promises for Webpack 2
- [Webpack 2] Tree shaking with Webpack 2
- [Webpack 2] Validate your Webpack config with webpack-validator
- (二)webpack入门——webpack的使用
- (一)webpack入门——webpack的安装
- Grunt、gulp、webpack、不要听着高大上你就上,试试Codekit?
- webpack
- [Webpack 2] Intro to the Production Webpack Course
- [转]webpack 使用优化指南
- webpack 多entry 配置
- webpack打包压缩工具的使用方法
- webpack es6支持配置
- webPack 使用方便快捷
- webpack loader 列表
- webpack进阶构建项目(一)
- 实用的webpack 配置文件
- webpack学习笔记一(入门)