嵌入式ember-cli项目与RequireJS冲突 [英] Embedded ember-cli project conflicts with RequireJS

查看:176
本文介绍了嵌入式ember-cli项目与RequireJS冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将EmberJS应用程序嵌入到大型门户应用程序中,该应用程序广泛使用RequireJS库.我正在使用ember-cli构建项目.生成的应用程序由两个文件dist/assets/vendor.jsdist/assets/myapp.js组成.嵌入后,EmberJS应用程序可以工作,但门户应用程序的javascript会中断.

I'm trying to embed an EmberJS application into a large portal application which uses extensively the RequireJS library. I'm using ember-cli to build the project. The built application consists of two files, dist/assets/vendor.js and dist/assets/myapp.js. The EmberJS application works after embedding it but the portal app's javascript breaks.

经过研究,我发现问题是vendor.js定义了自己的变量requirerequirejsrequireModuledefine,它们与全局命名空间中的网站变量冲突.然后,myapp.js文件包含define语句,这些语句将加载应用程序的模块.

After some research I've found out the problem is that vendor.js defines its own variables require, requirejs, requireModule and define which conflict with the website's variables in the global namespace. The myapp.js file then contains define statements which load the app's modules.

是否可以重命名这些文件或将它们放入其他不同的命名空间?

Is there a way to rename these or to put them into some different namespace?

我想到的唯一解决方案是手动重命名两个.js文件中的变量.这似乎可行,但是相当麻烦,并且如果可以自动化的话,那就太好了.我还发现了有关使用RequireJS优化器的信息,但无法使其与vendor.js文件一起使用.

The only solution I came up with was to manually rename the variables within the two .js files. This seems to work but it's rather cumbersome and it'd be nice if it could be automated. I have also found out about using RequireJS optimizer but I can't get it to work with the vendor.js file.

你能帮我吗? 谢谢!

推荐答案

我遇到了同样的问题,经过大量搜索,我相信我设法通过添加

I was having the same problem, and after much searching I believe I managed to solve it by adding the ember-derequire addon to my project:

ember install ember-derequire

这会将您应用中的所有"require"和"define"语句更改为"eriuqer"和"enifed".如果您不喜欢eriuqer和enifed,则可以使用选项覆盖它映射的内容(注意,您必须使用相同长度的东西).

That will change all of the 'require' and 'define' statements in your app to 'eriuqer' and 'enifed'. You can override what it maps to using options (caveat being you have to use something the same length) if you don't like eriuqer and enifed.

以防万一,我发现的另一个有希望的事情是 loader.js 具有noConflict()函数,但是我不知道将loader.noConflict()调用放在哪里,或者无法使用备用名称生成该版本来生成代码,但是如果第一个选项没有,它可能会为您提供帮助不能适应您的情况.

In case that doesn't help, the other promising thing I found is that loader.js has a noConflict() function, but I couldn't figure out where to put the loader.noConflict() call, or get the build to generate code using alternate names, but maybe it will help you if the first option doesn't work for your situation.

这篇关于嵌入式ember-cli项目与RequireJS冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆