javascript - 未捕获的 ReferenceError:jquery 未在 Object.766 中定义(外部“jquery.js”:1)
问题描述
我正在使用DLL方法打包jQuery库但浏览器一直报错这是我的webpack.config.js文件和webpack.dll.js文件和index.js文件
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const AddAssetHtmlWebpackPlugin = require('add-asset-html-webpack-plugin')
module.exports = {
entry: './src/js/index.js',
output: {
filename: 'js/bundle.js',
path: path.resolve(__dirname, 'dist'),
clean:true
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
scriptLoading: 'blocking'
}),
new webpack.DllReferencePlugin({
manifest:path.resolve(__dirname,'dll/manifest.json')
}),
new AddAssetHtmlWebpackPlugin({
filepath: path.resolve(__dirname, 'dll/jquery.js'),
publicPath: './',
})
],
mode: 'production',
devtool:'source-map'
};
const { resolve } = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
jquery:['jquery']
},
output: {
filename: '[name].js',
path: resolve(__dirname, 'dll'),
library: '[name]_[hash]',
},
plugins: [
new webpack.DllPlugin({
name: '[name].js',
path: resolve(__dirname, 'dll/manifest.json')
})
],
mode:'production'
}
import $ from 'jquery'
console.log($);
webpack打包过程没有错,文件应该是在正确的目录下生成的,引用过程没有错,但是就是不知道为什么浏览器一直报错,谁能帮我解决这个问题
解决方案
推荐阅读
- reactjs - 处理Graphql Mutation update,缓存读写查询,如果查询是动态的?
- java - 使用堆栈测试字符串是否为回文
- java - 如何将 ferrari 和 rollsroyce 类别添加到我的 ArrayList
- python - 将 pandas 交叉表合并到数据表并获得部分结果
- mysql - MySQL,根据两张表获取数据
- mobile - Flutter 移动 Web 材质图标
- java - 如果 pay=false,为什么我的代码无法读取?它只是跳过它并在 pay = false 时打印成本而不是最终成本
- visual-studio-code - 在 vscode 扩展 api 的工作区中创建的新文件的侦听器
- javascript - 用锚标记替换 DOM 文本
- php - 如何使用 GuzzleHttp 与 API 通信