javascript - 将所有默认 JS 文件从基本模板导入到 Webpack
问题描述
我正在尝试通过基于下载的模板(来自themeforest.net)开始一个新项目来学习 Webpack。
该模板包含许多 JS 文件(如 jquery.js、functions.js、plugins.animations.js 等),我想要对它们进行 webpacking,但是当我尝试使用 Jquery 构建 bundle.js 文件时出现错误。
webpack.config.js看起来像:
module.exports = {
entry: path.resolve(__dirname, "apex/static/js/index.js"),
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "apex/static/dist")
},
};
index.js看起来像:
require('./jquery.js');
require('./plugins.min.js');
require('./functions.js');
require('./custom.js');
当我重新加载包含 bundle.js 的 HTML 模板时,出现错误:
plugins.min.js:1 Uncaught ReferenceError: jQuery is not defined
at eval (plugins.min.js:1)
at Object../apex/static/js/plugins.min.js (bundle.js:48)
at __webpack_require__ (bundle.js:82)
at eval (index.js:3)
at Object../apex/static/js/index.js (bundle.js:38)
at __webpack_require__ (bundle.js:82)
at bundle.js:118
at bundle.js:120
所以我尝试包含第一个 jquery.js 和 bundle.js 之后像这样(仅用于测试):
<script src="js/jquery.js"></script>
<script src="dist/bundle.js"></script>
我有一个新错误:
jquery.js:2 jQuery.Deferred exception: jRespond is not defined ReferenceError: jRespond is not defined
at Object.defaults (webpack://django-webpack2/./apex/static/js/functions.js?:245:15)
at Object.init (webpack://django-webpack2/./apex/static/js/functions.js?:88:25)
at HTMLDocument.init (webpack://django-webpack2/./apex/static/js/functions.js?:2024:25)
at e (http://localhost/static/js/jquery.js:2:30038)
at t (http://localhost/static/js/jquery.js:2:30340) undefined
S.Deferred.exceptionHook @ jquery.js:2
t @ jquery.js:2
setTimeout (async)
(anonymous) @ jquery.js:2
c @ jquery.js:2
fireWith @ jquery.js:2
fire @ jquery.js:2
c @ jquery.js:2
fireWith @ jquery.js:2
ready @ jquery.js:2
B @ jquery.js:2
jquery.js:2 Uncaught ReferenceError: jRespond is not defined
at Object.defaults (functions.js:245)
at Object.init (functions.js:88)
at HTMLDocument.init (functions.js:2024)
at e (jquery.js:2)
at t (jquery.js:2)
我尝试通过 npm 安装 jquery 并将其包含在 webpack.config.js 中:
resolve: {
alias: {
jquery: "jquery/src/jquery"
}
}
而且错误...
plugins.min.js:1 Uncaught ReferenceError: jQuery is not defined
at eval (plugins.min.js:1)
at Object../apex/static/js/plugins.min.js (bundle.js:58)
at __webpack_require__ (bundle.js:1152)
at eval (index.js:3)
at Object../apex/static/js/index.js (bundle.js:38)
at __webpack_require__ (bundle.js:1152)
at bundle.js:1188
at bundle.js:1190
eval @ plugins.min.js:1
./apex/static/js/plugins.min.js @ bundle.js:58
__webpack_require__ @ bundle.js:1152
eval @ index.js:3
./apex/static/js/index.js @ bundle.js:38
__webpack_require__ @ bundle.js:1152
(anonymous) @ bundle.js:1188
(anonymous) @ bundle.js:1190
你能帮我吗 ?我学到的所有教程都从头开始新项目......
谢谢你的时间!
解决方案
推荐阅读
- postgresql - 将数组传递给 JDBC 中的 postgres
- database - 记录器/数据存储推荐
- python - Django 表单不显示多个表单,多个表单呈现到单个视图中的模板
- windows - Amazon.KinesisFirehose.AmazonKinesisFirehoseException:签名已过期
- sql - 如何同时/并行执行多个 Oracle 存储过程以获得更好的性能?
- javascript - 如何将容器 div 包裹在 Ckeditor 表上 onOk
- android-studio - Android Studio 3.4 卡在索引项目上
- java - Spring 中对 List 或 Map 的响应正文
- javascript - 在 webpack 构建中包含捆绑的 webpack 文件
- angular - 如何更改 Angular Material Datepicker 主题?