这两天试着把我的脚手架项目webpack-seed升级到webpack2,发现了一个问题:我用来兼容jquery插件的expose-loader在webpack2的环境下报错了。由于expose-loader最近并未更新,所以更别提更新官方文档了,github上放着的还是webpack1时的示例代码,所以我是这么用的: { test: require.resolve('jquery'),
loader: 'expose-loader?$',
options: {
$: true,
},
},然后编译打包的时候就报了如下的错误:ERROR in ./~/jquery/dist/jquery.jsModule build failed: TypeError: this.query.substr is not a function at Object.module.exports.pitch (I:\XAMPP\htdocs\webpack-seed\node_modules\expose-loader\index.js:26:34) @ ./src/pages/alert/index/page.js 1:0-17感觉上是loader的参数没能传得进去,因此敢问各位大兄弟,可有成功在webpack2环境下使用expose-loader的?另外附上webpack1的用法:{ test: require.resolve("jquery"), loader: "expose-loader?$!expose-loader?jQuery" },
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
试试这么写, 在我工程里好用的:
module: {
rules: [
{
test: /\.less$/,
use: Extract.extract({fallbackLoader: 'style-loader', loader: ["css-loader", "less-loader"]})
},
{test: require.resolve("jquery"), use: "expose-loader?$"},
{test: require.resolve("jquery"), use: "expose-loader?jQuery"},
{test: require.resolve("react"), use: "expose-loader?React"},
{test: require.resolve("react-dom"), use: "expose-loader?ReactDOM"},
{test: require.resolve("underscore"), use: "expose-loader?_"}
]
}
添加回答
举报
0/150
提交
取消