Javascript 如何将遗留jQuery插件与webpack捆绑
我正在尝试为我开发的web应用程序优化一些页面,第一件显而易见的事情是将js库捆绑在一起。然而,我无法实现这一点与网页。例如,我有一个Javascript 如何将遗留jQuery插件与webpack捆绑,javascript,webpack,Javascript,Webpack,我正在尝试为我开发的web应用程序优化一些页面,第一件显而易见的事情是将js库捆绑在一起。然而,我无法实现这一点与网页。例如,我有一个Feed.html页面,该页面使用以下库(为简洁起见,请保持列表简短): 插件/select2/3.5.4/select2.min.js 插件/bootstrap-daterangepicker/2.0.11/moment.min.js 插件/bootstrap-daterangepicker/2.0.11/daterangepicker.js 我希望webp
Feed.html
页面,该页面使用以下库(为简洁起见,请保持列表简短):
- 插件/select2/3.5.4/select2.min.js
- 插件/bootstrap-daterangepicker/2.0.11/moment.min.js
- 插件/bootstrap-daterangepicker/2.0.11/daterangepicker.js
Feed.js
,这样我就可以包含这个单独的js文件,而不是单独包含其中的每个文件
由于我们使用的大多数插件都是遗留插件,因此它们不遵守常见的JS/AMD/UMD模式,而是作为页面上的简单标签使用。根据这些信息,我找到了webpack的脚本加载器
,但它似乎没有任何作用
Page/Feed.js
webpack.config.js
Bundles/Feed.js
webpack似乎只是将
页面/Feed.js
作为捆绑包中的字符串输出。如何实现文件的这种连接?您是否解决过这个问题。我刚刚开始这段旅程,面临着同样的问题,在如何处理这一问题上经验有限
require("script!../plugins/select2/3.5.4/select2.min.js");
require("script!../plugins/bootstrap-daterangepicker/2.0.11/moment.js");
require("script!../plugins/bootstrap-daterangepicker/2.0.11/daterangepicker.js");
module.exports = {
entry: {
Feed: './Page/Feed.js'
},
output: {
filename: '[name].js',
path: './Bundles/'
},
};
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
__webpack_require__(1)(__webpack_require__(2))
/***/ },
/* 1 */
/***/ function(module, exports) {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = function(src) {
if (typeof execScript === "function")
execScript(src);
else
eval.call(null, src);
}
/***/ },
/* 2 */
/***/ function(module, exports) {
module.exports = "require(\"script!../plugins/select2/3.5.4/select2.min.js\");\r\nrequire(\"script!../plugins/bootstrap-daterangepicker/2.0.11/moment.js\");\r\nrequire(\"script!../plugins/bootstrap-daterangepicker/2.0.11/daterangepicker.js\");\r\n\r\n"
/***/ }
/******/ ]);