You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You may need to include additional files in your application bundle that aren't part of your frontend (your `frontendDist`) directly or which are too big to be inlined into the binary. We call these files `resources`.
7
9
8
-
To bundle the files of your choice, you can add the `resources` property to the `bundle` object in your `tauri.conf.json` file.
10
+
## Configuration
9
11
10
-
See more about `tauri.conf.json`configuration [here][tauri.bundle].
12
+
To bundle the files of your choice, add the `resources` property to the `bundle` object in your `tauri.conf.json`file.
11
13
12
-
`resources` expects a list of strings targeting files or directories either with absolute or relative paths. It supports glob patterns in case you need to include multiple files from a directory.
14
+
To include a list of files:
13
15
14
-
Here is a sample to illustrate the configuration. This is not a complete `tauri.conf.json` file:
16
+
<TabssyncKey="explanation">
17
+
<TabItemlabel="Syntax">
15
18
16
19
```json title=tauri.conf.json
17
20
{
18
21
"bundle": {
19
22
"resources": [
23
+
"./path/to/some-file.txt",
24
+
"/absolute/path/to/textfile.txt",
25
+
"../relative/path/to/jsonfile.json",
26
+
"some-folder/",
27
+
"resources/**/*.md"
28
+
]
29
+
}
30
+
}
31
+
```
32
+
33
+
</TabItem>
34
+
<TabItemlabel="Explanation">
35
+
36
+
```json title=tauri.conf.json5
37
+
{
38
+
"bundle": {
39
+
"resources": [
40
+
// Will be placed to `$RESOURCE/path/to/some-file.txt`
41
+
"./path/to/some-file.txt",
42
+
43
+
// The root in an abosolute path will be replaced by `_root_`,
44
+
// so `textfile.txt` will be placed to `$RESOURCE/_root_/absolute/path/to/textfile.txt`
20
45
"/absolute/path/to/textfile.txt",
21
-
"relative/path/to/jsonfile.json",
22
-
"resources/**/*"
46
+
47
+
// `..` in a relative path will be replaced by `_up_`,
48
+
// so `jsonfile.json` will be placed to `$RESOURCE/_up_/relative/path/to/textfile.txt`,
49
+
"../relative/path/to/jsonfile.json",
50
+
51
+
// If the path is a directory, the entire directory will be copied to the `$RESOURCE` directory,
52
+
// preserving the original structures, for example:
Alternatively the `resources` config also accepts a map object if you want to change where the files will be copied to. Here is a sample that shows how to include files from different sources into the same `resources` folder:
69
+
</TabItem>
70
+
</Tabs>
71
+
72
+
The bundled files will be in `$RESOURCES/` with the original directory structure preserved,
73
+
for example: `./path/to/some-file.txt` -> `$RESOURCE/path/to/some-file.txt`
74
+
75
+
To fine control where the files will get copied to, use a map instead:
In Tauri's [permission system](/reference/acl/capability/), absolute paths and paths containing parent components (`../`) can only be allowed via `"$RESOURCE/**"`. Relative paths like `"path/to/file.txt"` can be allowed explicitly via `"$RESOURCE/path/to/file.txt"`.
103
+
// `jsonfile.json` will be placed to `$RESOURCE/resources/jsonfile.json`
To learn about where `$RESOURCE` resolves to on each platforms, see the documentation of [`resource_dir`]
127
+
128
+
<details>
129
+
<summary>Source path syntax</summary>
49
130
50
131
In the following explanations "target resource directory" is either the value after the colon in the object notation, or a reconstruction of the original file paths in the array notation.
51
132
@@ -56,19 +137,111 @@ In the following explanations "target resource directory" is either the value af
56
137
-`"dir/**/*"`: copies all files in the `dir` directory _recursively_ (all files in `dir/` and all files in all sub-directories) into the target resource directory.
57
138
-`"dir/**/**`: throws an error because `**` only matches directories and therefore no files can be found.
58
139
59
-
## Accessing files in Rust
140
+
</details>
141
+
142
+
## Resolve resource file paths
143
+
144
+
To resolve the path for a resource file, instead of manually calculating the path, use the following APIs
60
145
61
-
In this example we want to bundle additional i18n json files that look like this:
146
+
<TabssyncKey="lang">
147
+
<TabItemlabel="Rust">
62
148
63
-
```json title=de.json
149
+
On the Rust side, you need an instance of the [`PathResolver`] which you can get from [`App`] and [`AppHandle`],
For the JavaScript side, you can either use a command like the one above and call it through `await invoke('hello')` or access the files using the [`plugin-fs`]
285
+
For the JavaScript side, you can either use a command like the one above and call it through `await invoke('hello')` or access the files using the [`fs` plugin].
107
286
108
-
When using the [`plugin-fs`], addition from the [basic setup], you'll also need to configure the access control list to enable any [`plugin-fs`] APIs you will need as well as permissions to access the `$RESOURCE` folder:
287
+
When using the [`fs` plugin], in addition to the [basic setup], you'll also need to configure the access control list to enable any plugin APIs you need as well as the permissions to access the `$RESOURCE` folder:
0 commit comments