配置providePlugin打包成功,执行错误
来源:4-4 文件处理(4)- 处理第三方 JS 库(providePlugin、imports-loader)
一顿吃八个饼
2018-05-08
package.json
{
"name": "use-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^8.4.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.11",
"cssnano": "^3.10.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"glob-all": "^3.1.0",
"images-webpack-loader": "^2.1.0",
"img-loader": "^3.0.0",
"less": "^3.0.2",
"less-loader": "^4.1.0",
"node-sass": "^4.9.0",
"postcss": "^6.0.22",
"postcss-cssnext": "^3.1.0",
"postcss-loader": "^2.1.4",
"purifycss-webpack": "^0.7.0",
"sass-loader": "^7.0.1",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"webpack": "^3.10.0",
"webpack-cli": "^2.0.15"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"babel-runtime": "^6.26.0",
"jquery": "^3.3.1",
"lodash": "^4.17.10",
"lodash-es": "^4.17.10"
},
"browserslist": [
">= 2%",
"last 2 versions"
]
}webpack.config.js 的plugins
plugins: [
new ExtractTextWebpackPlugin({
filename: '[name].min.css',
allChunks: false
}),
new webpack.ProvidePlugin({
_: 'lodash'
}),
// new webpack.optimize.UglifyJsPlugin(),
]app.js
console.log(_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 }))提示错误
Uncaught TypeError: $export is not a function

使用import引入lodash不会报错。注释掉ProvidePlugin的配置后不会报错
写回答
1回答
-
qbaty
2018-05-14
不明白,为什么你会报执行的错误,你可以console.log(_) 先确定一下你引入的lodash 是否成功
00
相似问题