unreact/config.rs
1use crate::{Port, DEFAULT_PORT, DEFAULT_PORT_WS};
2
3/// Configuration struct for `Unreact`
4///
5/// Use `Config::default()` for default values
6///
7/// ## Summary
8///
9/// - `strict`: Whether [`Handlebars`](handlebars) uses 'strict mode'
10/// - `minify`: Whether output files should be minified
11///
12/// Folders:
13///
14/// - `build`: Output folder for built files
15/// - `templates`: Source folder for template files
16/// - `styles`: Source folder for style files
17/// - `public`: Source folder for static public files
18///
19/// > Note that `styles` and `public` folders in *build directory* **cannot** be configured.
20///
21/// Development Options:
22///
23/// - `port`: Port to serve *dev server* on - Only used with `"dev"` feature
24/// - `port_ws`: Port to serve *dev server* **websockets** on - Only used with `"watch"` feature
25/// - `watch_logs`: Whether to log update information - Only used with `"watch"` feature
26#[derive(Debug)]
27pub struct Config {
28 /// Output folder for built files
29 ///
30 /// Overridden with DEV_BUILD_DIR if in dev mode
31 ///
32 /// Subfolders of build directory cannot be configured
33 ///
34 /// Default: `build` (or `.devbuild` in dev mode)
35 pub build: String,
36 /// Source folder for template files
37 ///
38 /// Default: `templates`
39 pub templates: String,
40 /// Source folder for style files
41 ///
42 /// Default: `styles`
43 pub styles: String,
44 /// Source folder for static public files
45 ///
46 /// Default: `public`
47 pub public: String,
48
49 /// Whether [`Handlebars`](handlebars) uses 'strict mode'
50 ///
51 /// If `true`, undefined variables and partials throw an error
52 pub strict: bool,
53 /// Whether output files should be minified
54 ///
55 /// Only affects `html` and `css` output files
56 pub minify: bool,
57
58 /// Port for main *dev server* to be hosted on
59 ///
60 /// Only used with `"dev"` feature, but must be defined always
61 pub port: Port,
62 /// Port for websocket server to be hosted on
63 ///
64 /// Only used with `"watch"` feature, but must be defined always
65 pub port_ws: Port,
66}
67
68impl Default for Config {
69 fn default() -> Self {
70 Self {
71 //? Move to const in lib.rs ?
72 build: "build".to_string(),
73 templates: "assets/templates".to_string(),
74 styles: "assets/styles".to_string(),
75 public: "assets/public".to_string(),
76
77 strict: false,
78 minify: true,
79
80 port: DEFAULT_PORT,
81 port_ws: DEFAULT_PORT_WS,
82 }
83 }
84}