webpack打包第三方类库有两种比较不错的方式:
- 第一种:
- 安装第三方库(jQuery)
npm i -S jquery
- 修改index.js文件(入口文件)
import $ from 'jquery'

结果:

- 第二种:
- 安装第三方库
- 使用webpack.config.js全局引入
- 全局引入使用
ProvidePlugin
插件,这是webpack自带的插件,所以在webpack.config.js要先引入webpack
- 全局引入使用
const webpack = requery("webpack")
然后我们再配置plugins模块,代码如下:
plugins: [
// new Uglify()
new webpack.ProvidePlugin({
$: "jquery"
})
]

结果:

网友评论