js-framework-file.md 3.5 KB
Newer Older
G
ge-yafang 已提交
1
# File Organization
Z
zengyawen 已提交
2

G
ge-yafang 已提交
3
## Directory Structure
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
The following figure shows the typical directory structure of the JavaScript module \(**entry/src/main/js/module**\) for an application with feature abilities \(FA\) using JavaScript APIs.
Z
zengyawen 已提交
6

E
ester.zhou 已提交
7
**Figure 1** Directory structure
Z
zengyawen 已提交
8

E
ester.zhou 已提交
9
![unnaming-(1)](figures/unnaming-(1).png)
Z
zengyawen 已提交
10

E
ester.zhou 已提交
11
**Figure 2** Directory structure for resource sharing<sup>5+</sup>  
G
ge-yafang 已提交
12

E
ester.zhou 已提交
13
![directory-structure-for-resource-sharing-5+](figures/directory-structure-for-resource-sharing-5+.png)
Z
zengyawen 已提交
14 15 16

Functions of the files are as follows:

G
ge-yafang 已提交
17 18
-   .hml  files describe the page layout.
-   .css  files describe the page style.
E
ester.zhou 已提交
19
-   .js  files process the page logic and user interactions .
Z
zengyawen 已提交
20 21 22

Functions of the folders are as follows:

E
ester.zhou 已提交
23
-   The **app.js** file manages global JavaScript logics and application lifecycle. For details, see [app.js](js-framework-js-file.md).
E
ester.zhou 已提交
24 25 26 27
-   The **pages** directory stores all component pages.
-   The **common** directory stores public resource files, such as media resources, custom components,  and  .js  files.
-   The **resources** directory stores resource configuration files, for example, for multi-resolution loading. For details, see  [Resource Limitations and Access](js-framework-resource-restriction.md).
-   The **share** directory<sup>5+</sup>  is used to configure resources shared by multiple instances. For example, images and JSON files in this directory can be shared by **default1** and **default2** instances.
Z
zengyawen 已提交
28

E
ester.zhou 已提交
29 30
>**NOTE** 
>
31
>-   The **i18n** and **resources** folders cannot be renamed.
E
ester.zhou 已提交
32 33
>-   If the same resource name and directory are used under the  share  directory and the instance \(**default**\) directory, the resource in the instance directory will be used when you reference the directory.
>-   The **share** directory does not support **i18n**.
Z
zengyawen 已提交
34 35
>-   You should create the optional folders \(shown in the directory structure\) as needed after you create the project in DevEco Studio.

G
ge-yafang 已提交
36
## File Access Rules
Z
zengyawen 已提交
37

G
ge-yafang 已提交
38
Application resources can be accessed via an absolute or relative path. In the JS UI framework, an absolute path starts with a slash \(/\), and a relative path starts with  ./  or  ../. The rules are as follows:
Z
zengyawen 已提交
39

E
ester.zhou 已提交
40 41
-   To reference a code file, use a relative path, for example, **../common/utils.js**.
-   To reference a resource file, use an absolute path, for example, **/common/xxx.png**.
E
ester.zhou 已提交
42
-   Store code files and resource files in the **common** directory and access the files in a required fashion.
E
ester.zhou 已提交
43
-   In a  .css  file, use the  url\(\)  function to create a URL, for example, **url\(/common/xxx.png\)**.
Z
zengyawen 已提交
44

E
ester.zhou 已提交
45
>**NOTE** 
E
ester.zhou 已提交
46
>
Z
zengyawen 已提交
47
>When code file A needs to reference code file B:
G
ge-yafang 已提交
48
>
Z
zengyawen 已提交
49 50
>-   If code files A and B are in the same directory, you can use either a relative or absolute path in code file B to reference resource files.
>-   If code files A and B are in different directories, you must use an absolute path in code file B to reference resource files because the directory of code file B changes during Webpack packaging.
G
ge-yafang 已提交
51 52 53 54
>-   Use an absolute path if you want to dynamically change the resource file path through data binding in a  .js  file.

## Media File Formats

E
ester.zhou 已提交
55
**Table 1** Supported image formats
G
ge-yafang 已提交
56 57 58 59 60 61 62 63 64

| Image Format | File Format |
| ------------ | ----------- |
| BMP          | .bmp        |
| GIF          | .gif        |
| JPEG         | .jpg        |
| PNG          | .png        |
| WebP         | .webp       |

E
ester.zhou 已提交
65
**Table 2** Supported video formats
G
ge-yafang 已提交
66

E
ester.zhou 已提交
67
| Video Format                    | File Format |
G
ge-yafang 已提交
68 69
| ------------------------------- | ----------- |
| H.264 AVC Baseline Profile (BP) | .3gp .mp4   |
Z
zengyawen 已提交
70