Skip to content

Commit

Permalink
rename frontendDist to prodFrontend?
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 2, 2024
1 parent 8350097 commit ef7394f
Show file tree
Hide file tree
Showing 40 changed files with 319 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .changes/config-restructure-rfc-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Restructured Tauri config per [RFC#5](https://github.com/tauri-apps/rfcs/blob/f3
- Removed `package` object.
- Renamed `tauri` object to `app`.
- Moved `tauri.bundle` object to the top-level.
- Renamed `build.distDir` field to `frontendDist`.
- Renamed `build.distDir` field to `prodFrontend`.
- Renamed `build.devPath` field to `devUrl` and will no longer accepts paths, it will only accept URLs.
- Moved `tauri.pattern` to `app.security.pattern`.
- Removed `tauri.bundle.updater` object, and its fields have been moved to the updater plugin under `plugins.updater` object.
Expand Down
8 changes: 4 additions & 4 deletions core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
path::PathBuf,
};
use tauri_codegen::{context_codegen, ContextData};
use tauri_utils::config::{AppUrl, WebviewUrl};
use tauri_utils::config::ProdFrontend;

// TODO docs
/// A builder for generating a Tauri application context during compile time.
Expand Down Expand Up @@ -82,11 +82,11 @@ impl CodegenContext {
let (config, config_parent) = tauri_codegen::get_config(&self.config_path)?;

// rerun if changed
match &config.build.frontend_dist {
Some(AppUrl::Url(WebviewUrl::App(p))) => {
match &config.build.prod_frontend {
Some(ProdFrontend::Dist(p)) => {
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
}
Some(AppUrl::Files(files)) => {
Some(ProdFrontend::Files(files)) => {
for path in files {
println!(
"cargo:rerun-if-changed={}",
Expand Down
31 changes: 14 additions & 17 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tauri_utils::acl::capability::Capability;
use tauri_utils::acl::plugin::Manifest;
use tauri_utils::acl::resolved::Resolved;
use tauri_utils::assets::AssetKey;
use tauri_utils::config::{AppUrl, Config, PatternKind, WebviewUrl};
use tauri_utils::config::{Config, PatternKind, ProdFrontend};
use tauri_utils::html::{
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
};
Expand Down Expand Up @@ -157,24 +157,21 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
options = options.with_csp();
}

let assets = match &config.build.frontend_dist {
let assets = match &config.build.prod_frontend {
Some(url) => match url {
AppUrl::Url(url) => match url {
WebviewUrl::External(_) | WebviewUrl::CustomProtocol(_) => Default::default(),
WebviewUrl::App(path) => {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `{}` configuration is set to `{:?}` but this path doesn't exist",
if dev { "devPath" } else { "distDir" },
path
)
}
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
ProdFrontend::Url(_url) => Default::default(),
ProdFrontend::Dist(path) => {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `{}` configuration is set to `{:?}` but this path doesn't exist",
if dev { "devPath" } else { "distDir" },
path
)
}
_ => unimplemented!(),
},
AppUrl::Files(files) => EmbeddedAssets::new(
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
}
ProdFrontend::Files(files) => EmbeddedAssets::new(
files
.iter()
.map(|p| config_parent.join(p))
Expand Down
58 changes: 43 additions & 15 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config",
"description": "The Tauri configuration object. It is read from a file where you can define your frontend assets, configure the bundler and define a tray icon.\n\nThe configuration file is generated by the [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in your Tauri application source directory (src-tauri).\n\nOnce generated, you may modify it at will to customize your Tauri application.\n\n## File Formats\n\nBy default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\nTauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively. The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`. The TOML file name is `Tauri.toml`.\n\n## Platform-Specific Configuration\n\nIn addition to the default configuration file, Tauri can read a platform-specific configuration from `tauri.linux.conf.json`, `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json` (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used), which gets merged with the main configuration object.\n\n## Configuration Structure\n\nThe configuration is composed of the following objects:\n\n- [`package`](#packageconfig): Package settings - [`app`](#appconfig): The Tauri config - [`build`](#buildconfig): The build configuration - [`plugins`](#pluginconfig): The plugins config\n\n```json title=\"Example tauri.config.json file\" { \"productName\": \"tauri-app\", \"version\": \"0.1.0\" \"build\": { \"beforeBuildCommand\": \"\", \"beforeDevCommand\": \"\", \"devUrl\": \"../dist\", \"frontendDist\": \"../dist\" }, \"app\": { \"security\": { \"csp\": null }, \"windows\": [ { \"fullscreen\": false, \"height\": 600, \"resizable\": true, \"title\": \"Tauri App\", \"width\": 800 } ] }, \"bundle\": {} } ```",
"description": "The Tauri configuration object. It is read from a file where you can define your frontend assets, configure the bundler and define a tray icon.\n\nThe configuration file is generated by the [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in your Tauri application source directory (src-tauri).\n\nOnce generated, you may modify it at will to customize your Tauri application.\n\n## File Formats\n\nBy default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\nTauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively. The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`. The TOML file name is `Tauri.toml`.\n\n## Platform-Specific Configuration\n\nIn addition to the default configuration file, Tauri can read a platform-specific configuration from `tauri.linux.conf.json`, `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json` (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used), which gets merged with the main configuration object.\n\n## Configuration Structure\n\nThe configuration is composed of the following objects:\n\n- [`package`](#packageconfig): Package settings - [`app`](#appconfig): The Tauri config - [`build`](#buildconfig): The build configuration - [`plugins`](#pluginconfig): The plugins config\n\n```json title=\"Example tauri.config.json file\" { \"productName\": \"tauri-app\", \"version\": \"0.1.0\" \"build\": { \"beforeBuildCommand\": \"\", \"beforeDevCommand\": \"\", \"devUrl\": \"../dist\", \"prodFrontend\": { \"dist\": \"../dist\" }, }, \"app\": { \"security\": { \"csp\": null }, \"windows\": [ { \"fullscreen\": false, \"height\": 600, \"resizable\": true, \"title\": \"Tauri App\", \"width\": 800 } ] }, \"bundle\": {} } ```",
"type": "object",
"properties": {
"$schema": {
Expand Down Expand Up @@ -1097,18 +1097,18 @@
]
},
"devUrl": {
"description": "The URL to load in development.\n\nThis is usually an URL to a dev server, which serves your application assets with hot-reload and HMR. Most modern JavaScript bundlers like [vite](https://vitejs.dev/guide/) provides a way to start a dev server by default.\n\nIf you don't have a dev server or don't want to use one, ignore this option and use [`frontendDist`](BuildConfig::frontend_dist) and point to a web assets directory, and Tauri CLI will run its built-in dev server and provide a simple hot-reload experience.",
"description": "The URL to load in development.\n\nThis is usually an URL to a dev server, which serves your application assets with hot-reload and HMR. Most modern JavaScript bundlers like [vite](https://vitejs.dev/guide/) provides a way to start a dev server by default.\n\nIf you don't have a dev server or don't want to use one, ignore this option and use [`prodFrontend`](BuildConfig::prod_frontend) and point to a web assets directory, and Tauri CLI will run its built-in dev server and provide a simple hot-reload experience.",
"type": [
"string",
"null"
],
"format": "uri"
},
"frontendDist": {
"prodFrontend": {
"description": "The path to the application assets (usually the `dist` folder of your javascript bundler) or a URL that could be either a custom protocol registered in the tauri app (for example: `myprotocol://`) or a remote URL (for example: `https://site.com/app`).\n\nWhen a path relative to the configuration file is provided, it is read recursively and all files are embedded in the application binary. Tauri then looks for an `index.html` and serves it as the default entry point for your application.\n\nYou can also provide a list of paths to be embedded, which allows granular control over what files are added to the binary. In this case, all files are added to the root and you must reference it that way in your HTML files.\n\nWhen a URL is provided, the application won't have bundled assets and the application will load that URL by default.",
"anyOf": [
{
"$ref": "#/definitions/AppUrl"
"$ref": "#/definitions/ProdFrontend"
},
{
"type": "null"
Expand Down Expand Up @@ -1161,23 +1161,51 @@
},
"additionalProperties": false
},
"AppUrl": {
"ProdFrontend": {
"description": "Defines the URL or assets to embed in the application.",
"anyOf": [
"oneOf": [
{
"description": "The app's external URL, or the path to the directory containing the app assets.",
"allOf": [
{
"$ref": "#/definitions/WebviewUrl"
"description": "An external URL to load.",
"type": "object",
"required": [
"url"
],
"properties": {
"url": {
"type": "string",
"format": "uri"
}
]
},
"additionalProperties": false
},
{
"description": "Path to the folder containing the frontend dist assets.",
"type": "object",
"required": [
"dist"
],
"properties": {
"dist": {
"type": "string"
}
},
"additionalProperties": false
},
{
"description": "An array of files to embed on the app.",
"type": "array",
"items": {
"type": "string"
}
"type": "object",
"required": [
"files"
],
"properties": {
"files": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
]
},
Expand Down
38 changes: 24 additions & 14 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,19 +1710,22 @@ fn default_min_sdk_version() -> u32 {
/// Defines the URL or assets to embed in the application.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(untagged, deny_unknown_fields)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[non_exhaustive]
pub enum AppUrl {
/// The app's external URL, or the path to the directory containing the app assets.
Url(WebviewUrl),
pub enum ProdFrontend {
/// An external URL to load.
Url(Url),
/// Path to the folder containing the frontend dist assets.
Dist(PathBuf),
/// An array of files to embed on the app.
Files(Vec<PathBuf>),
}

impl std::fmt::Display for AppUrl {
impl std::fmt::Display for ProdFrontend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Url(url) => write!(f, "{url}"),
Self::Dist(p) => write!(f, "{}", p.display()),
Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
}
}
Expand Down Expand Up @@ -1778,7 +1781,7 @@ pub struct BuildConfig {
/// This is usually an URL to a dev server, which serves your application assets with hot-reload and HMR.
/// Most modern JavaScript bundlers like [vite](https://vitejs.dev/guide/) provides a way to start a dev server by default.
///
/// If you don't have a dev server or don't want to use one, ignore this option and use [`frontendDist`](BuildConfig::frontend_dist)
/// If you don't have a dev server or don't want to use one, ignore this option and use [`prodFrontend`](BuildConfig::prod_frontend)
/// and point to a web assets directory, and Tauri CLI will run its built-in dev server and provide a simple hot-reload experience.
#[serde(alias = "dev-url")]
pub dev_url: Option<Url>,
Expand All @@ -1796,7 +1799,7 @@ pub struct BuildConfig {
/// When a URL is provided, the application won't have bundled assets
/// and the application will load that URL by default.
#[serde(alias = "frontend-dist")]
pub frontend_dist: Option<AppUrl>,
pub prod_frontend: Option<ProdFrontend>,
/// A shell command to run before `tauri dev` kicks in.
///
/// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
Expand Down Expand Up @@ -1922,7 +1925,9 @@ where
/// "beforeBuildCommand": "",
/// "beforeDevCommand": "",
/// "devUrl": "../dist",
/// "frontendDist": "../dist"
/// "prodFrontend": {
/// "dist": "../dist"
/// },
/// },
/// "app": {
/// "security": {
Expand Down Expand Up @@ -2003,7 +2008,7 @@ fn default_build() -> BuildConfig {
BuildConfig {
runner: None,
dev_url: None,
frontend_dist: None,
prod_frontend: None,
before_dev_command: None,
before_build_command: None,
before_bundle_command: None,
Expand Down Expand Up @@ -2335,14 +2340,19 @@ mod build {
}
}

impl ToTokens for AppUrl {
impl ToTokens for ProdFrontend {
fn to_tokens(&self, tokens: &mut TokenStream) {
let prefix = quote! { ::tauri::utils::config::AppUrl };
let prefix = quote! { ::tauri::utils::config::ProdFrontend };

tokens.append_all(match self {
Self::Url(url) => {
let url = url_lit(url);
quote! { #prefix::Url(#url) }
}
Self::Dist(path) => {
let path = path_buf_lit(path);
quote! { #prefix::Dist(#path) }
}
Self::Files(files) => {
let files = vec_lit(files, path_buf_lit);
quote! { #prefix::Files(#files) }
Expand All @@ -2354,7 +2364,7 @@ mod build {
impl ToTokens for BuildConfig {
fn to_tokens(&self, tokens: &mut TokenStream) {
let dev_url = opt_lit(self.dev_url.as_ref().map(url_lit).as_ref());
let frontend_dist = opt_lit(self.frontend_dist.as_ref());
let prod_frontend = opt_lit(self.prod_frontend.as_ref());
let runner = quote!(None);
let before_dev_command = quote!(None);
let before_build_command = quote!(None);
Expand All @@ -2366,7 +2376,7 @@ mod build {
::tauri::utils::config::BuildConfig,
runner,
dev_url,
frontend_dist,
prod_frontend,
before_dev_command,
before_build_command,
before_bundle_command,
Expand Down Expand Up @@ -2614,7 +2624,7 @@ mod test {
let build = BuildConfig {
runner: None,
dev_url: None,
frontend_dist: None,
prod_frontend: None,
before_dev_command: None,
before_build_command: None,
before_bundle_command: None,
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ impl<R: Runtime> AppManager<R> {
/// Get the base path to serve data from.
///
/// * In dev mode, this will be based on the `devUrl` configuration value.
/// * Otherwise, this will be based on the `frontendDist` configuration value.
/// * Otherwise, this will be based on the `prodFrontend` configuration value.
#[cfg(not(dev))]
fn base_path(&self) -> Option<&Url> {
use crate::{utils::config::AppUrl, WebviewUrl};
match self.config.build.frontend_dist.as_ref() {
match self.config.build.prod_frontend.as_ref() {
Some(AppUrl::Url(WebviewUrl::External(url) | WebviewUrl::CustomProtocol(url))) => Some(url),
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ fn main() {
&& current_url.domain() == protocol_url.domain()
}) ||

// or if relative to `devUrl` or `frontendDist`
// or if relative to `devUrl` or `prodFrontend`
self
.manager()
.get_url()
Expand Down
6 changes: 4 additions & 2 deletions core/tauri/test/fixture/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"$schema": "../../../../../core/tauri-config-schema/schema.json",
"identifier": "studio.tauri.example",
"build": {
"frontendDist": "../dist",
"prodFrontend": {
"dist": "../dist"
},
"devUrl": "http://localhost:4000"
},
"app": {
Expand All @@ -18,4 +20,4 @@
"bundle": {
"active": true
}
}
}
25 changes: 19 additions & 6 deletions examples/api/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"version": "1.0.0",
"identifier": "com.tauri.api",
"build": {
"frontendDist": "../dist",
"prodFrontend": {
"dist": "../dist"
},
"devUrl": "http://localhost:1420",
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn build"
Expand All @@ -22,16 +24,23 @@
"csp": {
"default-src": "'self' customprotocol: asset:",
"connect-src": "ipc: http://ipc.localhost",
"font-src": ["https://fonts.gstatic.com"],
"font-src": [
"https://fonts.gstatic.com"
],
"img-src": "'self' asset: http://asset.localhost blob: data:",
"style-src": "'unsafe-inline' 'self' https://fonts.googleapis.com"
},
"freezePrototype": true,
"assetProtocol": {
"enable": true,
"scope": {
"allow": ["$APPDATA/db/**", "$RESOURCE/**"],
"deny": ["$APPDATA/db/*.stronghold"]
"allow": [
"$APPDATA/db/**",
"$RESOURCE/**"
],
"deny": [
"$APPDATA/db/*.stronghold"
]
}
}
}
Expand All @@ -51,7 +60,11 @@
"name": "theme",
"takesValue": true,
"description": "App theme",
"possibleValues": ["light", "dark", "system"]
"possibleValues": [
"light",
"dark",
"system"
]
},
{
"short": "v",
Expand Down Expand Up @@ -93,4 +106,4 @@
}
}
}
}
}
Loading

0 comments on commit ef7394f

Please sign in to comment.