1

我在尝试在我的项目中使用 Alertify 时遇到了麻烦。我正在使用 symfony 4 中的 webpack encore。

我已安装使用:

npm install alertifyjs --save

这是我的 app.js

    // any CSS you require will output into a single css file (app.css in this case)
import '../css/app.css';
import '../../node_modules/bootstrap/dist/css/bootstrap.css';
import '../../node_modules/admin-lte/bower_components/font-awesome/css/font-awesome.min.css';
import '../../node_modules/admin-lte/bower_components/Ionicons/css/ionicons.min.css';
import '../../node_modules/admin-lte/dist/css/AdminLTE.min.css';
import '../../node_modules/admin-lte/dist/css/skins/skin-blue.min.css';

const $ = require('jquery');
global.$ = global.jquery = $;

import 'bootstrap';
import '../../node_modules/admin-lte/bower_components/jquery-ui/jquery-ui.js';
import '../../node_modules/admin-lte/dist/js/adminlte.js';


const alertify = require('alertifyjs');
global.alertify = alertify;
// Custom js
import './dashboard/GMDashboard.js';
import './explotations/GMExplotations.js';

在我尝试使用的对象上,您可以看到我正在将窗口、jQuery 和 alertify 传递给闭包以在内部使用它们,但只是我收到了这个错误:

GMExplotations.js:37 未捕获的 ReferenceError:alertify 未在对象中定义。(GMExplotations.js:37) 在 Object../assets/js/explotations/GMExplotations.js (app.js:327) 在webpack_require (bootstrap:78) 在模块。(app.js:1) 在 Module../assets/js/app.js (app.js:23) 在webpack_require (bootstrap:78) 在 checkDeferredModules (bootstrap:45) 在 bootstrap:151 在 bootstrap:151

'use strict';

(function(window, $, alertify) {

    window.GMExplotations = function($wrapper) {
        console.log($wrapper);
        this.$wrapper = $wrapper;

        //TODO: Bind events

        // App Init
        this.init();
    };

    $.extend(window.GMExplotations.prototype, {

        _selectors: {

        },

        init: function() {
            console.log('Alertify test');
            alertify
                .alert("This is an alert dialog.", function(){
                    alertify.message('OK');
                });
        },

    });

    let ExplotationsWrapper = $('#explotations-table');

    if (ExplotationsWrapper.length > 0) {
        let GM = new GMExplotations(ExplotationsWrapper);
    }

})(window, jQuery, alertify); <- Here fails

Alertifyjs 在我的 vendor~app.js 上,但我不知道为什么它找不到 alertify,知道吗?

4

0 回答 0