doc04 - KoreaSenchaUserGroup/Lab1 GitHub Wiki
μλ¬Έ : http://docs.sencha.com/touch/2-0/#!/guide/building
λ²μ : μ κ±΄μ° [Github:NangChun]
Sencha Touch 2 comes with a brand new class system that features an ability to dynamically load classes when they are needed. This has many benefits in both development and production.
In development, dynamic loading means you get a file-by-file stack trace, which makes it much easier to debug problems with your application. For production, we provide a build tool that enables you to easily create a minified custom build that only includes the classes your app actually uses, meaning loading times are often reduced for your users.
νμν λ λμ μΌλ‘ ν΄λμ€λ₯Ό λ‘λνλ λ₯λ ₯μ κ°μΆ μλ‘μ΄ μ’ λ₯μ ν΄λμ€ μμ€ν κ³Ό ν¨κ» μΌμ°¨ν°μΉ2κ° μ 곡λ©λλ€. κ°λ°κ³Ό μμ°μ± λͺ¨λ λ§μ μ₯μ μ΄ μμ΅λλ€.
κ°λ°μμλ, λμ λ‘λ©μ νμΌκ° μ€ν μΆμ μ μ»μ μ μμμ μλ―Ένλ©°, ν¨μ¬ μ½κ² μμ© νλ‘κ·Έλ¨ λ¬Έμ λ₯Ό λλ²κΉ ν μ μμ΅λλ€. μ μμ μν΄μ , customλΉλλ₯Ό μ±μ΄ μ€μ§μ μΌλ‘ μ¬μ©νλ ν΄λμ€λ₯Ό ν¬ν¨νμ¬ μΆμνκ³ λΉλλ₯Ό κ°λ₯ν μ½κ² λ§λλ λꡬλ₯Ό μ 곡νλ©°, μ£Όλ‘ μ¬μ©μλ₯Ό μν λ‘λ©μκ° κ°μλ₯Ό λͺ©μ μΌλ‘ ν©λλ€.
Sencha Touch 2 ships with 5 builds out of the box. If you just want to get up and running as quickly as possible it's best to simply use sencha-touch-debug.js while developing your app locally then switch to sencha-touch.js in production. The other three builds are good for debugging in production, running in production without a custom build, and migrating your 1.x app to 2.x. Because each build is good for a different purpose an created using a different set of build options we've created a simple table below that shows how each one is configured:
Name | Type | Loader | Minified | Comments | Debug | Compat | Usage |
---|---|---|---|---|---|---|---|
sencha-touch-debug.js | Core | β | β | β | Use when developing your app locally | ||
sencha-touch.js | Core | β | β | Use in production with a custom build | |||
builds/sencha-touch-all.js | All | β | Use in production if you don't have a custom build | ||||
builds/sencha-touch-all-debug.js | All | β | β | Use to debug your app in staging/production | |||
builds/sencha-touch-all-compat.js | All | β | β | β | Use to migrate your 1.x app to 2.x |
Note that the last 3 builds are contained within the 'builds' directory in the SDK download. If the table above is not self-explanatory, here's a little more detail on what each option means:
- Type: either "Core" or "All" - Core includes the base classes but none of the Components, All means everything is included
- Loader: whether dynamic loading is activated or not. Only sencha-touch.js has this activated by default
- Minified: means the build has been compressed with YUI compressor
- Comments: means the build still contains the JSDoc comments (these are usually stripped in production to speed up downloads)
- Debug: means that the build will give you debug messages such as telling you if you have misconfigured a class
- Compat: means that code to provide backwards compatibility with Sencha Touch 1.x is present in the build
Again, use sencha-touch-debug.js in development mode then switch to either sencha-touch.js or sencha-touch-all.js plus a custom build in production.
μΌμ°¨ν°μΉ2λ 5κ°μ§ λΉλλ€κ³Ό ν¨κ» μΆμλ©λλ€. κΉ¨μ°κ³ μ΅λν λΉ λ₯΄κ² μ€ννλ €λ μκ°μΌ κ²½μ° κ°λ¨ν sencha-touch.jsλ₯Ό μ¬μ©νκ³ μ μμμ λ‘컬μμ μ±μ κ°λ° ν λλ©΄ sencha-touch-debug.jsλ‘ μ ννμ¬ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. μ μν λ λλ²κΉ μ μ’μ λ€λ₯Έ μΈκ°μ§ λΉλλ, custom λΉλ μμ΄λ μ μνμ¬ μ€νλ©λλ€, κ·Έλ¦¬κ³ 1.x μμ 2.xλ‘ μ΄μ ν©λλ€. κ° λΉλλ λ€λ₯Έ λͺ©μ μ μν΄ μλ κ²μ΄κΈ° λλ¬Έμ μλμ κ°λ¨ν ν μ΄λΈμ μμ±ν΄ μ΅μ μ λΉλμ κ°κΈ° λ€λ₯Έ μΈνΈ νλνλλ‘ κ΅¬μ±νλ λ°©λ²μ μ¬μ©νμ¬ λ§λλ κ²μ΄ μ’λ€λ κ²μ λ³΄μ¬ μ€λλ€ :
μ΄λ¦ | μ’ λ₯ | λ‘λ | μΆμλ¨ | μ£Όμ | λλ²κ·Έ | μ½€ν» | μ¬μ©λ² |
---|---|---|---|---|---|---|---|
sencha-touch-debug.js | μ½μ΄ | β | β | β | λ‘컬 μ± κ°λ°μ μ¬μ© | ||
sencha-touch.js | μ½μ΄ | β | β | custom λΉλμ ν¨κ» μ μμ μ¬μ© | |||
builds/sencha-touch-all.js | μ λΆ | β | custom λΉλκ° μλ€λ©΄ μ μμ μ¬μ© | ||||
builds/sencha-touch-all-debug.js | μ λΆ | β | β | μμλ‘ / μ μνλ μ±μ λλ²κΉ νλλ° μ¬μ© | |||
builds/sencha-touch-all-compat.js | μ λΆ | β | β | β | 1.x μ± μμ 2.xλ‘ μ΄μ νκΈ° μν΄ μ¬μ© |
λ§μ§λ§ 3κ°μ§ λΉλλ SDK λ€μ΄λ‘λ μμ 'λΉλ'λλ ν 리 λ΄μ ν¬ν¨λμ΄ μλμ§ μ°Έκ³ ν©λλ€. λ€λ§ μμ ν μ΄λΈλ‘ μ΄ν΄κ° μλ κ²½μ°, μ¬κΈ°μ μ’λ μμΈν κ°κ°μ μ΅μ μ μλ―Έλ₯Ό μμ μμ΅λλ€:
- μ’ λ₯: "μ½μ΄"λλ "μ λΆ" μ€ νλ μ λλ€ - μ½μ΄λ κΈ°λ³Έ ν΄λμ€λ ν¬ν¨λμμΌλ μ»΄ν¬λνΈκ° μμΌλ©°, μ λΆλ λͺ¨λ κ²μ ν¬ν¨νμλ€λ μλ―Έ
- λ‘λ: λμ λ‘λ©μ΄ νμ±ν λμλ μ§μ λν μ¬λΆμ λλ€. sencha-touch.js λ§μ΄ κΈ°λ³Έμ μΌλ‘ νμ±ν
- μΆμλ¨: YUI μμΆκΈ°λ‘ λΉλκ° μμΆλμμμ μλ―Έ
- μ£Όμ: λΉλκ° μμ§ JSDoc μ£Όμμ΄ μμ§ ν¬ν¨λμμμ μλ―Έ (λ³΄ν΅ λ€μ΄λ‘λ μλλ₯Ό λμ΄κΈ° μν΄ μ μμ μ μΈ)
- λλ²κ·Έ: λΉλκ° μλͺ» ꡬμ±λ ν΄λμ€κ° μμ κ²½μ°λ₯Ό λ§νλ λ±μ λλ²κ·Έ λ©μμ§κ° μ 곡 λλ€λ κ²μ μλ―Έ
- Compat: μΌμ°¨ν°μΉ1.x κ³Ό ν¨κ» νμ νΈνμ±μ μ 곡νλ μ½λκ° λΉλμ μ‘΄μ¬ν¨μ μλ―Έ
λ€μ, μ μμ€μ sencha-touch.js λλ sencha-touch-all.js μ€ νλλ₯Ό κ°λ°μ λͺ¨λμμ sencha-touch-debug.js λ‘ μ ννμ¬ μ¬μ©ν©λλ€.
In the vast majority of cases a Sencha Touch 2 app should use a custom build in production, for 2 main reasons:
- Custom builds include only the framework classes your app is actually using, saving on download time
- A custom build includes all of your app classes in a single file, which means only one network request
Reason 2 is especially important. Most applications will have a large number of files (sometimes hundreds), and loading them one by one, especially over a 3g network, can take a long time. That's because each request can add several hundred milliseconds of delay, depending on network conditions, which can easily add several seconds to your application's overall load time.
To ensure your applications load quickly in production we have created the Sencha SDK Tools, which includes a build script that automatically does all of this:
- Figures out which framework classes your application is actually using
- Figures out which application classes are loaded when your application boots up
- Combines all of these into a single file, with the classes in the right order
- Strips out all of the JSDoc comments, then minifies the file so it's as small as possible
If you don't already have the Sencha SDK Tools installed, you'll need to install them before you can create a build. A quick way to check to see if the tools are already installed is to open up your command line terminal and type in 'sencha' - if the SDK Tools are present you should see something like this:
Output of running 'sencha' on the command line if the SDK Tools are installed
If you get an error instead you probably don't have the SDK Tools installed. Just hit the download button on http://www.sencha.com/products/sdk-tools, double-click the downloaded file to install then try the sencha command again and everything should work.
** Note: ** The build steps are expected to be simplified in the next release (2.0.0 Beta 2) so please check this page again once that release is available.
We're going to assume you have an app that works locally already and that you just want to build it for production. If you don't have an app yet or don't know what this is all about, check out the getting started guide.
Assuming you app does work locally though, let's proceed. We're going to use the Twitter example that comes with the Sencha Touch SDK to illustrate how this works. Firstly let's familiarize ourselves with that example's index.html file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Twitter</title>
<link rel="stylesheet" href="resources/css/application.css" type="text/css">
<script type="text/javascript" src="touch/sencha-touch-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
Notice that we're loading sencha-touch-debug.js and app.js - this combination is what allows us to use dynamic loading while developing our app, and is the basis for the SDK Tools' ability to generate a minimal build. We'll come back to this html file's contents shortly.
Back to the command line - first you'll need to cd into to the directory that your app can be found in on your hard drive:
cd ~/path/to/my/app
Next you'll need to generate a jsb file for your app. A jsb file is basically a list of all the classes that your application uses. Thankfully, the SDK Tools do this for you:
sencha create jsb -a index.html -p app.jsb3
This command takes your index.html file (the same file you use in your browser while developing your app), figures out all of the class dependencies and writes them out into a file called app.jsb3. From here we just need one more command to actually generate the build itself:
sencha build -p app.jsb3 -d ./
This final command takes all of the files listed in the jsb and combines them into a single file, which it then minifies to make as small as possible. The output is a file called all-classes.js, which contains all of the framework classes plus your application classes.
The final step to prepare your app for production is to update your HTML file to use sencha-touch.js instead of sencha-touch-debug.js, and to load your newly-generated all-classes.js. Here's how our twitter example file ends up:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Twitter</title>
<link rel="stylesheet" href="resources/css/application.css" type="text/css">
<script type="text/javascript" src="touch/sencha-touch.js"></script>
<script type="text/javascript" src="all-classes.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
Rather than change your main index.html file all the time, it's common to create a duplicate called index-production.html that looks like the file above. Many developers will produce a simple deploy script that copies the app into a deploy folder and renames index-production.html to index.html automatically so that the build can simply be uploaded.
Although it's only a few steps, we'd like to improve both the workflow and the output of the builder for the next release of Sencha Touch. If you're building using Sencha Touch 2.0 beta 1 please be sure to check back when you upgrade to a later release as it is likely the steps and output will have changed slightly.
λλΆλΆμ κ²½μ° μΌμ°¨ν°μΉ2 μ±μ μ μμ custom λΉλλ₯Ό μ¬μ©νκ³ μμ κ²μ΄λ©°, 2κ°μ§ μ΄μ λλ¬Έμ λλ€ :
- custom λΉλλ μ±μ μ€μ λ‘ μ¬μ©νλ κ²½μ°μλ§ νλ μμν¬ ν΄λμ€κ° ν¬ν¨λ©λλ€, λ€μ΄λ‘λ μκ°μ μ μ½ν©λλ€
- custom λΉλλ νλμ νμΌμμ μμ© νλ‘κ·Έλ¨μ ν΄λμ€λ₯Ό λͺ¨λ ν¬ν¨, μ΄κ²μ νλμ λ€νΈμν¬λ§ μμ²ν¨μ μλ―Έν©λλ€
2μ μ΄μ λ μ€μν©λλ€. λλΆλΆμ μ ν리μΌμ΄μ μ λ§μμμ νμΌμ(λλ‘λ μλ°±μ) κ°μ ΈμΌ νκ³ , νλμ© λ‘λ νλ©°, νΉν 3g λ€νΈμν¬λ₯Ό ν΅ν΄μ, μκ°μ΄ μ€λ 걸릴 μ μμ΅λλ€. λ€νΈμν¬ μ‘°κ±΄μ λ°λΌ, κ° μμ²μ΄ μλ°± λ°λ¦¬μ΄λ₯Ό μΆκ°λ‘ μ§μ° μν¬μ μκΈ° λλ¬Έμ, μμ© νλ‘κ·Έλ¨μ μ 체μ μΈ λ‘λμκ°μ λͺμ΄ μ λ μ½κ² μΆκ°ν μ μμ΅λλ€.
μ μ μ€ μμ©νλ‘κ·Έλ¨μ μ μν λ‘λλ₯Ό 보μ₯νκΈ°μν΄ SDK λꡬλ₯Ό λ§λ€μμ΅λλ€, λ€μ λΉλ μ€ν¬λ¦½νΈλ₯Ό λͺ¨λ μλμΌλ‘ ν¬ν¨ν©λλ€:
- νλ μμν¬ ν΄λμ€μμ μ ν리μΌμ΄μ μ΄ μλμΌλ‘ μ¬μ©λ¨μ κ³μ°νκΈ°
- μ ν리μΌμ΄μ μ΄ κΉ¨μ΄λ λ μ ν리μΌμ΄μ ν΄λμ€μμ λ‘λλλ κ²μ κ³μ°νκΈ°
- μ΄λ€μ νλμ νμΌμ, λͺ¨λ λ°λ₯Έ μμλλ‘ ν΄λμ€μ ν¨κ» κ²°ν©νκΈ°
- JSDocμ μ½λ©νΈλ₯Ό λͺ¨λ μ κ±°, νμΌμ΄ κ°λ₯ν μμμ§κ² μΆμ
μΌμ°¨ SDK λκ΅¬κ° μ€μΉλμ§ μμ κ²½μ°, λΉλλ₯Ό μμ±νκΈ° μ μ μ€μΉ λμ΄ μμ΄μΌ ν©λλ€. λκ΅¬κ° μ΄λ―Έ μ€μΉλμ΄ μλμ§ νμΈνλ λΉ λ₯Έ λ°©λ²μ 컀맨λ λΌμΈ ν°λ―Έλμ μ΄κ³ 'sencha' λ₯Ό μ λ ₯ν©λλ€ - SDK λκ΅¬κ° μ‘΄μ¬νλ€λ©΄ μ΄λ κ² λνλ©λλ€ :
SDK λκ΅¬κ° μ€μΉλ κ²½μ° μ»€λ§¨λ λΌμΈμμ 'sencha'κ° μ€ν μ€ μμ μΆλ ₯
μ€λ₯κ° μλ€λ©΄ μλ§λ λκ² SDK λκ΅¬κ° μ€μΉλμ΄ μμ§ μμ κ² μ λλ€. κ·Έλ₯ http://www.sencha.com/products/sdk-toolsμμ λ€μ΄λ‘λ λ²νΌμ λλ₯΄κ³ λ€μ΄λ‘λν νμΌμ λλΈν΄λ¦νλ©΄ λ€μ μΌμ°¨ μ€μΉ λͺ λ Ήμ μλν ν λͺ¨λ μλν κ²μ λλ€.
** μ°Έμ‘°: ** λΉλ λ¨κ³ λ€μ λ¦΄λ¦¬μ¦ (2.0.0 λ² ν 2)μμ λ¨μνκ² μμ λ κ²λ 릴리μ¦λ₯Ό μ¬μ©ν μ μλμ§ λ€μ ν λ² νμ΄μ§λ₯Ό νμΈνμκΈ° λ°λλλ€.
μ΄λ―Έ λ‘μ»¬λ‘ μλνλ μ±μ κ°μ§κ³ μμΌλ©° μ μνλ μκ°μ μν΄ λΉλνκΈΈ μνλ€κ³ κ°μ ν©λλ€. μ΄μ λν΄ λ¬΄μμΈμ§ λͺ¨λ₯΄κ±°λ μμ§ μ±μ΄ μλ€λ©΄, μμ κ°μ΄λλ₯Ό νμΈ νμμμ.
μ±μ΄ λ‘μ»¬μΈ κ²μ²λΌ κ°μ νμ¬, μ§νν©μλ€. μ΄λ»κ² μλνλμ§ μ€λͺ μΌλ‘ Sencha ν°μΉ SDKμ ν¨κ» μ 곡λλ νΈμν° μμ λ₯Ό μ¬μ© ν κ² μ λλ€. 첫λ²μ§Έλ‘ index.html νμ΄μ§ νμΌκ³Ό ν¨κ» μ€μ€λ‘ μ΅μν΄ μ§μλ€:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Twitter</title>
<link rel="stylesheet" href="resources/css/application.css" type="text/css">
<script type="text/javascript" src="touch/sencha-touch-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
sencha - ν°μΉ debug.js λ° app.jsμ λ‘λνκ³ μλμ§ μ£Όμ - μ΄ μ‘°ν©μ μ±μ κ°λ°νλ©΄μ λμ λ‘λλ₯Ό μ¬μ©ν μ μκ² ν΄ μ£Όλ κ²μ΄λ©°, κ·Έλ¦¬κ³ μ΅μνμ λΉλλ₯Ό μμ±νκΈ°μν SDK λꡬ λ₯λ ₯μ κΈ°μ΄μ λλ€. κ³§ μ΄λ¬ν HTML νμΌμ λ΄μ©μΌλ‘ λμμ¬ κ²μ λλ€.
컀맨λλΌμΈμΌλ‘ λμκ°μ - cdμ λν ν λ¦¬λ‘ νλ λλΌμ΄λΈμ μ±μ λ¨Όμ μ°ΎμμΌ ν©λλ€ :
cd ~/path/to/my/app
λ€μμ μ±μ μν jsb νμΌμ μμ±ν΄μΌν©λλ€. jsb νμΌμ κΈ°λ³Έμ μΌλ‘ μ±μμ μ¬μ©νλ λͺ¨λ ν΄λμ€μ λͺ©λ‘μ λλ€. λ€νν, SDK λκ΅¬λ‘ λ€μμ μνν©λλ€ :
sencha create jsb -a index.html -p app.jsb3
μ΄ λͺ λ Ήμ index.html νμΌ (μ±μ κ°λ°νλ©΄μ λΈλΌμ°μ μμ μ¬μ©νλ λμΌν νμΌ)μ κ°μ Έκ°κ³ , νΈμΆλ app.jsb3 νμΌμ μμ±νκ³ μ λΆ κ·Έ ν΄λμ€ μ’ μμΌλ‘ μ΄ν΄ν©λλ€ :
sencha build -p app.jsb3 -d ./
μ΅μ’ λͺ λ Ήμ jsbμ λμ΄λ λͺ¨λ νμΌμ μμνκ³ λμ μ΅λν μκ² λ§λ€κΈ° μν΄ μΆμλ νλμ νμΌμ κ²°ν© ν©λλ€. νλ μμν¬ ν΄λμ€ μΈμ μμ© νλ‘κ·Έλ¨ ν΄λμ€λ₯Ό λͺ¨λ ν¬ν¨νλ classes.jsλΌλ νμΌμ μΆλ ₯ν©λλ€.
λ§μ§λ§ λ¨κ³λ μ± μ μμ λν sencha-touch-debug.jsμ sencha-touch.jsλ₯Ό λμ μ¬μ©νκ³ λͺ¨λ classes.jsλ₯Ό μλ‘ μμ±νμ¬ λ‘λνλ HTML νμΌμ μ λ°μ΄νΈλ₯Ό μ€λΉνλ κ²μ λλ€. νΈμν° μμ νμΌμ λ§λ¬΄λ¦¬ νλ λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Twitter</title>
<link rel="stylesheet" href="resources/css/application.css" type="text/css">
<script type="text/javascript" src="touch/sencha-touch.js"></script>
<script type="text/javascript" src="all-classes.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
λ©μΈ index.html νμ΄μ§ νμΌμ λ΄λ΄ λ³κ²½ ν기보λ€, μμ νμΌκ³Ό λΉμ·ν index-production.htmlμ΄ νΈμΆλλ μ¬λ³Έμ λ§λλ κ²μ΄ μΌλ°μ μ λλ€. λ§μ κ°λ°μλ€μ μλμ μΌλ‘ κ·Έλ κ² λΉλλ₯Ό κ°λ¨νκ² μ¬λ¦΄ μ μλ index.htmlμ λ°°ν¬νλ ν΄λμ μ΄λ¦μ λ°κΏλλ€ index-production.htmlλ‘ μμ© νλ‘κ·Έλ¨μ 볡μ¬νλ κ°λ¨ν λ°°μΉ μ€ν¬λ¦½νΈλ₯Ό μμ±ν κ²μ λλ€.
λ¨ λͺ κ±Έμμ΄μ§λ§, μ°λ¦¬λ μν¬νλ‘μ°μ μΌμ°¨ν°μΉμ λ€μ 릴리μ€λ₯Ό μν λΉλμ μΆλ ₯μ λͺ¨λ κ°μ νκ³ μΆμ΅λλ€. μΌμ°¨ν°μΉ 2.0 λ² ν 1μ μ¬μ©νμ¬ κ΅¬μΆνλ κ²½μ°μλ κ·Έ κ°λ₯μ±μ΄ μλ λ¨κ³μ΄λ©°, μΆλ ₯μ΄ μ½κ° λ³κ²½λλλλ‘ λμ€μ 릴리μ€λ₯Ό μ κ·Έλ μ΄λνλ©΄ λ€μ νμΈν΄ μ£ΌμκΈ° λ°λλλ€.