javascript - 在 webpack 构建中只包含 jquery slim?
问题描述
如何在我的 webpack 构建中只包含 jquery slim?
现在,我正在包含这样的 jquery,它工作正常,但我不想加载整个库..
webpack.config.js
module.exports = {
...
module: {
rules: [
...
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
},
{
loader: 'expose-loader',
options: '$'
}]
}
]
...
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
}
}
我在 npm 中找不到官方的 jquery-slim 包,所以我想我的想法是安装整个 jquery 包,并且只使用我想要的东西,但我无法找到如何做到这一点。
解决方案
jquery-slim.js
在jquery
.
它在node_modules/jquery/dist/jquery-slim.js
。
所以你需要做的就是将加载器和插件指向jquery.slim.js
路径:
module.exports = {
...
module: {
rules: [
...
{
test: require.resolve('jquery/dist/jquery.slim'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
},
{
loader: 'expose-loader',
options: '$'
}]
}
]
...
plugins: [
new webpack.ProvidePlugin({
$: 'jquery/dist/jquery.slim',
jQuery: 'jquery/dist/jquery.slim'
})
]
}
}
推荐阅读
- javascript - 如何获取在 Chrome 标签中播放的音频名称
- javascript - 在 div 外部单击应该为 div 添加抖动效果;点击里面不应该有任何变化
- discord.py - 将排行榜分为页面 discord.py
- javascript - 顺序 API 调用,我使用 Promise.all 还是迭代函数?
- google-apps-script - Google 表格:具有动态变化的自定义功能
- javascript - TypeError:SnakeGame 不是构造函数
- php - 将旧的 mysql 调用重写为新的 mysqli_real_query
- amazon-web-services - 发送 POST 请求返回“文本为空”
- javascript - 如何获得全时使用 Javascript 显示
- javascript - 如何在不忽略重定向的情况下将道具传递给私有路由