简体   繁体   English

带定义/需求功能的requirejs冲突

[英]requirejs confilcts with define/require functions

so long story short - I have a problem trying to integrate requireJS in the old project with whole bunch of legacy code that has a definition for global define function which conflicts with requireJS. 这么长的话很短-我在尝试将旧项目中的requireJS与一堆旧代码集成在一起时遇到问题,这些遗留代码具有与requireJS冲突的全局定义函数的定义。 Problem happens in karma/jasmine test when I load those two scripts. 当我加载这两个脚本时,在业力/茉莉花测试中会出现问题。

karma.conf.js karma.conf.js

files: [
  <lib that has define global function insight>
  ...
  webappJs + '/vendor/require.js',
  'src/test/js/test-main.js',
  ... 
]

test-main.js test-main.js

var allTestFiles = [];
var TEST_REGEXP = /.*ng.*test\.js/i;

Object.keys(window.__karma__.files).forEach(function(file) {
    if (TEST_REGEXP.test(file)) {
        // Normalize paths to RequireJS module names.
        allTestFiles.push(file);
    }
});

var config = {
    appDir : '',
    baseUrl : '/base/src/main/webapp',
    dir: "lib",
    deps: allTestFiles,
    callback: window.__karma__.start,
    paths : {
        // Configure alias to full paths
        'angular' : 'lib/angular.min',
        'angularMock' : '/base/src/test/lib/angular-mocks',
        'requireLib': 'lib/require'
    },
    namespace: "appRequire",
    shim : {
        'angular' : {
            deps : [],
            exports : 'angular'
        },
        'angularMock' : {
            deps : ['angular']
        }
    },
    modules: [
        {
            name: "appRequire",
            include: ["requireLib"],
            create: true
        }
    ]
};

require.config (config);

so supposedly now I have to include the appRequire.js file ??? 所以应该是现在我必须包括appRequire.js文件? but here is the thing I don't understand how the module will be created, who will create it? 但是,我不了解如何创建模块,这是谁创建的? Should I not include require.js into list of files 我是否应该不在文件列表中包含require.js

The document doesn't say much about it...it just says that I'll be able to use define/require function as appRequire.define and appRequire.require after that...but what is the mechanism of that? 该文档没有对此进行过多说明...它只是说在那之后我将能够将define / require函数用作appRequire.define和appRequire.require ...但是那是什么机制? What do I miss here? 我在这里想念什么? Cause currently requirejs is still complaining about code that uses the 'old' define function. 由于当前requirejs仍在抱怨使用“旧”定义函数的代码。

Thanks in advance to all of you who can shed some light on that! 在此先感谢所有可以阐明这一点的人!

fixed this problem manually resolving the conflict in main.js 手动解决了这个问题,解决了main.js中的冲突

if( typeof define !== 'undefined' ) {
    myApp = {
       define : define
    };
    define = void 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM