ImmakinguseofRequireJs,andImhavingtroublewiththebuild.我正在使用RequireJs,而且我在构建过程中遇到了麻烦。
I'm making use of RequireJs, and I'm having trouble with the build.
我正在使用RequireJs,而且我在构建过程中遇到了麻烦。
My structure is
我的结构
webroot
css
/* css here */
files
img
js
emails
verify.js
lib
jquery-1.8.3.min.js
jquery-ui.min.js
jquery.ui.selectmenu.js
modernizr.js
require.js
orders
form.js
common.js
js-build
/* expected build output here */
js-tools
app.build.js
This is a part of a CakePHP project, but the webroot is where the actual webroot of the web server will be.
这是CakePHP项目的一部分,但是webroot是web服务器的实际webroot。
node and r.js.cmd are both on my path, so I haven't included it in the js-tools directory.
节点和r.js。cmd都在我的路径上,所以我没有将它包含在js-tools目录中。
When accessing the default page, the is /, but it could also appear as /orders/form. For this reason, relative Urls to the JS is an issue.
当访问默认页面时,是/,但也可以显示为/订单/表单。因此,对JS的相对url是一个问题。
When I load the JS, I'm using
当我加载JS时,我在使用。
This is taken from https://github.com/requirejs/example-multipage-shim.
这是取自https://github.com/requirejs/examplemultishim。
My common.js is
我常见。js是
requirejs.config({
"baseUrl": "/js/lib",
"paths": {
"orders": "../orders",
"emails": "../emails",
"jquery": [
"//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min",
"jquery-1.8.3.min"
],
"jquery-ui": [
"//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min",
"jquery-ui.min"
]
},
"shim": {
"jquery.ui.selectmenu": ["jquery", "jquery-ui"]
}
});
As it stands, this works when working with unoptimized code. The important feature is that js is referenced with an absolute URL, is it can be picked up by the code from either /, or /orders/form.
正如它所表明的那样,当使用未优化的代码时,这是有效的。重要的特性是,js使用一个绝对的URL来引用,它可以由来自任何/或/订单/表单的代码来获取。
My app.build.js is
我的app.build。js是
({
appDir: '..', /* relative to app.build.js */
mainConfigFile: '../js/common.js', /* relative to app.build.js */
baseUrl: 'js/lib', /* relative to current directory */
dir: '../js-build', /* relative to app.build.js */
optimize: 'uglify2',
paths: {
"jquery": "empty:",
"jquery-ui": "empty:",
"jquery.ui.selectmenu": "empty:",
"common": "../common",
"orders": "../orders",
"emails": "../emails"
},
modules: [
{
name: 'common',
include: [
'modernizr'
],
exclude: ['jquery-1.8.3.min', 'jquery-ui.min', 'jquery.ui.selectmenu']
},
{
name: 'orders/form',
exclude: ['common', 'jquery.ui.selectmenu']
},
{
name: 'emails/verify',
exclude: ['common', 'jquery.ui.selectmenu']
}
]
})
When optimization runs as r.js.cmd -o js-tools\app.build.js
from the webroot, I get a js-build directory with a copy of the whole webroot directory, optimized. Although not ideal (I wanted to limit it to just the js directory getting optimized), I can use my Ant driven build script to copy the contents of the js-build\js directory to the correct location.
当优化运行为r.js时。cmd - o js-tools \ app.build。在webroot中,我得到了一个js构建的目录,其中包含了整个webroot目录的副本,并进行了优化。虽然不理想(我希望将其限制为只对js目录进行优化),但我可以使用Ant驱动的构建脚本将js-build\js目录的内容复制到正确的位置。
When I run the build from the command line, the generated common.js, orders/form.js and emails/verify.js all exclude jquery.ui.selectmenu. common.js has modernizr included, as well as the header from the same lib. form.js and verify.js also exclude jquery.ui.selectmenu, and are devoid of any headers.
当我从命令行运行构建时,生成的common。js、订单/形式。js和电子邮件/验证。js jquery.ui.selectmenu排除。常见的。js包含了现代化的内容,也包括了来自相同的lib表单的标题。js和验证。js也排除jquery.ui。选择菜单,并且没有任何标题。
However, when I run from my Ant script, orders/form.js and emails/verify.js include jquery.ui.selectmenu and modernizr, even though I've given specific instruction for common and jquery.ui.selectmenu to be excluded.
然而,当我从我的Ant脚本运行时,命令/表单。js和电子邮件/验证。js包含jquery.ui。selectmenu和modernizr,尽管我已经给出了通用和jquery.ui的特定指令。selectmenu被排除在外。
I've excluded jquery.ui.selectmenu, because the particular version I am working with is written the the following form, and the browser has an issue with the end jQuery variable not being available. By excluding jquery.ui.selectmenu, I can attempt to load it separately, as though it came from a CDN.
我排除了jquery.ui。selectmenu,因为我正在处理的特定版本编写了以下表单,而浏览器有一个问题,即结束jQuery变量没有可用。jquery.ui除外。selectmenu,我可以尝试单独加载它,好像它来自一个CDN。
(function($, undefined) {
$.widget("ui.selectmenu", {...
});
}( jQuery ));
So, my issue is, how come the same app.build.js is resulting in different output?
所以,我的问题是,如何创建相同的应用程序。js会产生不同的输出吗?
1 个解决方案