[英]Swiper 8 with Webpack 5: Class not defined
I'm trying to use Swiper 8 with Webpack 5.我正在尝试将 Swiper 8 与 Webpack 5 一起使用。
In my Webpack config i defined two entry points:在我的 Webpack 配置中,我定义了两个入口点:
module.exports = {
entry: {
vendor: './vendor.js',
frontend: './frontend.js',
}
...
}
In the vendor.js I've imported Swiper:在 vendor.js 中,我导入了 Swiper:
import 'swiper/scss';
import Swiper from 'swiper';
In the frontend.js I've imported my script files:在 frontend.js 中,我导入了我的脚本文件:
import './custom.js'
No i try to initalize Swiper in my custom.js:不,我尝试在我的 custom.js 中初始化 Swiper:
const swiper = new Swiper('.swiper', {});
Here I get an error message:在这里我收到一条错误消息:
Uncaught ReferenceError: Swiper is not defined未捕获的 ReferenceError:未定义 Swiper
In my HTML file, I import the vendor.js before the frontend.js file.在我的 HTML 文件中,我在 frontend.js 文件之前导入了 vendor.js。 Theoretically, the Swiper class should be available to me.从理论上讲,我应该可以使用 Swiper class。 What am I doing wrong?我究竟做错了什么?
<script type="text/javascript" src="/dist/vendor.js"></script>
<script type="text/javascript" src="/dist/frontend.js"></script>
You will need to您将需要
import Swiper from 'swiper';
inside your custom.js , because, even though it is properly imported in frontend.js , it's not imported in custom.js and it is not seen there.在您的custom.js中,因为即使它在frontend.js中正确导入,它也没有在custom.js中导入,并且在那里看不到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.