webpack jplayer: 无法设置未定义的 属性 jplayer

webpack jplayer: Cannot set property jplayer of undefined

在使用 webpack 捆绑 js 文件时,库 jplayer 也被捆绑在 bundle.js 文件中。但是当网页在浏览器上加载时,它在控制台上显示 cannot set property jplayer of undefined 错误。我对错误是由于 webpack 还是 jplayer 库中存在错误感到困惑。 非常感谢帮助。

jplayer.js

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['jquery'], factory); // jQuery Switch
    // define(['zepto'], factory); // Zepto Switch
} else if (typeof exports === 'object') {
    // Node/CommonJS
    factory(require('jquery')); // jQuery Switch
    //factory(require('zepto')); // Zepto Switch
} else {
    // Browser globals
    if(root.jQuery) { // Use jQuery if available
        factory(root.jQuery);
    } else { // Otherwise, use Zepto
        factory(root.Zepto);
    }
}
}(this, function ($, undefined) {

// Adapted from jquery.ui.widget.js (1.8.7): $.widget.bridge - Tweaked $.data(this,XYZ) to $(this).data(XYZ) for Zepto
$.fn.jPlayer = function( options ) {    //cannot set property jplayer error is mapped here
    var name = "jPlayer";
    var isMethodCall = typeof options === "string",
        args = Array.prototype.slice.call( arguments, 1 ),
        returnValue = this;

    // allow multiple hashes to be passed on init
    options = !isMethodCall && args.length ?
        $.extend.apply( null, [ true, options ].concat(args) ) :
        options;

我今天遇到了同样的情况,在我重写了我的webpack配置之后。像我一样懒惰,我在 webpack-dev-server 和 webpack.

中使用相同的 webpack.config.json

我的问题发生在我这样拆分我的项目时:

// output for js
output: {
    path: path.join(__dirname + '/build'),
    filename: './res/js/[name]_[hash:10].js'
},

//output for html
var pages = getEntry(['./home/en/*.html','./home/cn/*.html'],'home/');
for (var chunkname in pages) {
    var conf = {
        filename: path.join(path.dirname(pages[chunkname]).replace('home/','build/'),path.basename(pages[chunkname])),
        template: pages[chunkname],
        favicon: './img/favicon.ico',
        inject: true,
        hash: true,
        minify: {
            removeComments: true,
            collapseWhitespace: true
        },
        chunks: ['vendor','css/[name].css', chunkname]
    };
    plugins.push(new HtmlWebpackPlugin(conf));

然后所有JS都出错了,控制台告诉我同样的错误。我检查了 _webpack_require_ 的功能,发现所有的地图编号都是错误的。

然后我查看了webpack_dev_server的日志,发现了这个:

               ..\build\en\aboutus-company.html    11.3 kB          [emitted]  
              ..\build\en\aboutus-news.html    6.26 kB          [emitted]  
           ..\build\en\aboutus-privacy.html    8.58 kB          [emitted]  
           ..\build\en\aboutus-service.html    10.7 kB          [emitted]  
                     ..\build\en\index.html    10.9 kB          [emitted]  
              ..\build\en\monetization.html    6.63 kB          [emitted]  
             ..\build\en\news-161017-1.html    7.76 kB          [emitted]  
             ..\build\en\news-161017-2.html    8.71 kB          [emitted]  
             ..\build\en\news-161017-3.html     9.9 kB          [emitted]  
                     ..\build\en\owner.html     5.9 kB          [emitted]  
                       ..\build\en\sdk.html    5.29 kB          [emitted]  
            ..\build\en\successstories.html    7.72 kB          [emitted]  
           ..\build\cn\aboutus-company.html    11.3 kB          [emitted]  
              ..\build\cn\aboutus-news.html    6.26 kB          [emitted]  
           ..\build\cn\aboutus-privacy.html    8.58 kB          [emitted]  
           ..\build\cn\aboutus-service.html    10.7 kB          [emitted]  
                     ..\build\cn\index.html    10.9 kB          [emitted]  
              ..\build\cn\monetization.html    6.63 kB          [emitted]  
             ..\build\cn\news-161017-1.html    7.76 kB          [emitted]  
             ..\build\cn\news-161017-2.html    8.71 kB          [emitted]  
             ..\build\cn\news-161017-3.html     9.9 kB          [emitted]  
                     ..\build\cn\owner.html     5.9 kB          [emitted]  
                       ..\build\cn\sdk.html    5.29 kB          [emitted]  
            ..\build\cn\successstories.html    7.72 kB          [emitted]  

它将文件发送到子文件夹中。当我尝试这条路时,一切顺利。