首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack jplayer:无法设置未定义的属性jplayer

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

Stack Overflow用户
提问于 2016-04-08 06:18:01
回答 1查看 233关注 0票数 0

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

jplayer.js

代码语言:javascript
复制
(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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-01 08:37:02

今天,在我重新写了webpack的配置之后,我也遇到了同样的情况。和我一样懒惰,我在webpack开发服务器和webpack中都使用相同的webpack.config.json。

当我像这样把我的项目分开的时候,我的问题就发生了:

代码语言:javascript
复制
// 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的日志,发现如下:

代码语言:javascript
复制
               ..\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]  

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36492831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档