简体   繁体   English

Amber Smalltalk - 创建单个.js文件以进行部署

[英]Amber Smalltalk - Creating a single .js file for deployment

I've seen this topic come up a couple times, but I don't think I've seen any definitive solution posted. 我已经看过这个话题了几次,但我认为我没有看到任何确定的解决方案。

I've tried the route of combining all my Foo.deploy.js, Bar.deploy.js into a single .js file, and then including that in the loadAmber() call. 我已经尝试了将所有我的Foo.deploy.js,Bar.deploy.js组合成单个.js文件的路由,然后将其包含在loadAmber()调用中。 This /seems/ to work reasonably well, but the majority of the download size still comes from Amber internals. 这/似乎/工作得相当好,但大部分下载大小仍然来自Amber内部。

In my application, the worst offenders in size are: 在我的申请中,规模最大的罪犯是:

  • 200K - jQuery UI 200K - jQuery UI
  • 95K - Kernel-Collections 95K - 内核集合
  • 90K - jQuery 90K - jQuery
  • 87K - Kernel-Objects 87K - 内核对象
  • 50K - Canvas 50K - 画布
  • 40K - MyApp 40K - MyApp
  • 20K - Kernel-Classes 20K - 内核类

I can't do too much about the size of jQuery UI, but I can do a lot about the size of the Amber core, and the number of HTTP requests needed to fetch them. 我不能对jQuery UI的大小做太多 ,但我可以做很多关于Amber核心的大小,以及获取它们所需的HTTP请求的数量。 The only problem is I cannot figure out how to tell Amber not to auto-matically fetch Kernel-Objects.deploy.js, etc. 唯一的问题是我无法弄清楚如何告诉Amber不要自动获取Kernel-Objects.deploy.js等。

Has anybody managed to package their entire Amber javascript into a single .js file successfully? 有没有人设法将他们的整个Amber javascript成功打包成一个.js文件?

  • R. Tyler Croy R.泰勒克罗伊

Code: http://github.com/rtyler Chatter: http://twitter.com/agentdero 代码: http//github.com/rtyler Chatter: http//twitter.com/agentdero

The Amber compiler can do quite a bit of stuff: Amber编译器可以做很多事情:

http://github.com/NicolasPetton/amber/blob/master/bin/amberc#L18-90 http://github.com/NicolasPetton/amber/blob/master/bin/amberc#L18-90

The following command will compile jQuery and the listed packages and generate amber-deploy.js: 以下命令将编译jQuery和列出的包并生成amber-deploy.js:

./bin/amberc -l js/lib/jQuery/jquery-1.6.4.min,Kernel-Objects.deploy,Kernel-Classes.deploy,Kernel-Methods.deploy,Kernel-Collections.deploy,Kernel-Exceptions.deploy,Canvas.deploy amber-deploy

Note the lack of spaces between listed filenames. 请注意列出的文件名之间缺少空格。

Also - you can download the Google Closure compiler http://closure-compiler.googlecode.com/files/compiler-latest.zip and put it in your home directory (~/compiler.jar) and then run (notice the -O option): 另外 - 您可以下载Google Closure编译器http://closure-compiler.googlecode.com/files/compiler-latest.zip并将其放在您的主目录(〜/ compiler.jar)中然后运行(注意-O选项):

./bin/amberc -O -l js/lib/jQuery/jquery-1.6.4.min,Kernel-Objects.deploy,Kernel-Classes.deploy,Kernel-Methods.deploy,Kernel-Collections.deploy,Kernel-Exceptions.deploy,Canvas.deploy amber-deploy

Then in your html you can just put: 然后在你的HTML中你可以放:

<script src='amber-deploy.js'></script>

Starting in Amber 0.13, you can use the RequireJS optimizer to create one minimized JS file, including your own code, Amber, and all dependencies. 从Amber 0.13开始,您可以使用RequireJS优化器创建一个最小化的JS文件,包括您自己的代码,Amber和所有依赖项。

To load Amber 0.13 alpha : 要加载Amber 0.13 alpha

(sudo) npm -g install amber-cli@~0.13.0  

The key is the build file. 关键是构建文件。 All RequireJS setup that used to go directly into index.html goes here. 以前直接进入index.html的所有RequireJS设置都在这里。 For example, a slightly customized app.build.js: 例如,稍微定制的app.build.js:

({
    mainConfigFile: "config.js",
    paths: {
        ... skipped items there by default
        'lib/jquery-migrate': 'bower_components/jquery/jquery-migrate'
    },
    "shim": {
        'lib/jquery-migrate': [ 'jquery' ]
    },
    include: [
        'amber/requirejs/require.min',
        'amber/deploy',
        'my-namespace/MyPackage',
        'lib/jquery-migrate'
    ],
    out: "all-in-1.js"
})

Now, running r.js -o app.build.js will now produce a single minified JS file named all-in-1.js, which is the only file you need to load from index.html 现在,运行r.js -o app.build.js现在将生成一个名为all-in-1.js的缩小JS文件,这是您需要从index.html加载的唯一文件

I believe the incantation is now supposed to be like this - 我相信咒语现在应该是这样的 -

./bin/amberc -m Counter st/Examples.st Onefile

... where I'm creating a single file distribution for the "Counter" example without actually instantiating a counter. ...我正在为“Counter”示例创建单个文件分发而不实际实例化计数器。 The output file will be "Onefile.js" which contains the necessary amber kernel classes as well as the Counter example class. 输出文件将是“Onefile.js”,其中包含必要的琥珀色内核类以及Counter示例类。

However, when I try to load Onefile.js, I get multiple "Maximum call stack size exceeded" errors in the JS console in Chrome and Safari on MacOSX. 但是,当我尝试加载Onefile.js时,我在Chrome和MacOSX上的Safari中的JS控制台中出现了多个“超出最大调用堆栈大小”错误。 While I feel the "one file to deploy" scenario is close to reality, there are still some warts to be healed. 虽然我觉得“一个文件要部署”的情景接近现实,但仍有一些疣要愈合。

Btw adding the "-O" flag to the above command like will result in the output file being passed through the google closure compiler whose path is expected to be in "~/compiler.jar". 顺便说一下,将“-O”标志添加到上面的命令会导致输出文件通过谷歌闭包编译器,其路径应该在“〜/ compiler.jar”中。 ie - 即 -

./bin/amberc -O -m Counter st/Examples.st Onefile

will result in a minimized single JS output file, which is nice. 将导致最小化的单个JS输出文件,这很好。

Amber version 0.13 released 琥珀版0.13发布

Amber Version 0.13 has been released . 琥珀版0.13已经发布

In this version the command 在这个版本的命令

amber init

creates creates among a number of other files a Gruntfile.js ( http://gruntjs.com/ ). 在许多其他文件中创建一个Gruntfile.js( http://gruntjs.com/ )。

With

 grunt deploy

on the command line your JavaScript file called the.js is changed to contain everything which is needed for deployment. 在命令行上,您的名为the.js的JavaScript文件已更改为包含部署所需的所有内容。

This means for deployment you only need 这意味着您只需要进行部署

  • index.html
  • the.js

to put in the target directory. 放入目标目录。

the.js contains only JavaScript. the.js只包含JavaScript。 No Smalltalk sources. 没有Smalltalk来源。

With

grunt develop

you switch back to development mode. 你切换回开发模式。 You get a short version of the.js 你得到了the.js的简短版本

Source: https://github.com/amber-smalltalk/amber/wiki/Deploying-Amber 资料来源: https//github.com/amber-smalltalk/amber/wiki/Deploying-Amber

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

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