-
Notifications
You must be signed in to change notification settings - Fork 399
/
mod.rs
91 lines (83 loc) · 2.93 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
#[cfg(feature = "deserialize_bundler_options")]
use schemars::JsonSchema;
#[cfg(feature = "deserialize_bundler_options")]
use serde::{Deserialize, Deserializer};
use crate::{ModuleType, SourceMapIgnoreList};
use self::types::{
input_item::InputItem, is_external::IsExternal, output_format::OutputFormat,
output_option::AddonOutputOption, platform::Platform, resolve_options::ResolveOptions,
source_map_type::SourceMapType, sourcemap_path_transform::SourceMapPathTransform,
};
pub mod types;
#[derive(Default, Debug)]
#[cfg_attr(
feature = "deserialize_bundler_options",
derive(Deserialize, JsonSchema),
serde(rename_all = "camelCase", deny_unknown_fields)
)]
pub struct BundlerOptions {
// --- options for input
pub input: Option<Vec<InputItem>>,
pub cwd: Option<PathBuf>,
#[cfg_attr(
feature = "deserialize_bundler_options",
serde(default, deserialize_with = "deserialize_external"),
schemars(with = "Option<Vec<String>>")
)]
pub external: Option<IsExternal>,
pub treeshake: Option<bool>,
pub platform: Option<Platform>,
pub shim_missing_exports: Option<bool>,
// --- options for output
pub entry_filenames: Option<String>,
pub chunk_filenames: Option<String>,
pub asset_filenames: Option<String>,
pub dir: Option<String>,
pub format: Option<OutputFormat>,
pub sourcemap: Option<SourceMapType>,
#[cfg_attr(
feature = "deserialize_bundler_options",
serde(default, deserialize_with = "deserialize_addon"),
schemars(with = "Option<String>")
)]
pub banner: Option<AddonOutputOption>,
#[cfg_attr(
feature = "deserialize_bundler_options",
serde(default, deserialize_with = "deserialize_addon"),
schemars(with = "Option<String>")
)]
pub footer: Option<AddonOutputOption>,
#[cfg_attr(
feature = "deserialize_bundler_options",
serde(default, skip_deserializing),
schemars(skip)
)]
pub sourcemap_ignore_list: Option<SourceMapIgnoreList>,
#[cfg_attr(
feature = "deserialize_bundler_options",
serde(default, skip_deserializing),
schemars(skip)
)]
pub sourcemap_path_transform: Option<SourceMapPathTransform>,
/// Key is the file extension. The extension should start with a `.`. E.g. `".txt"`.
pub module_types: Option<HashMap<String, ModuleType>>,
// --- options for resolve
pub resolve: Option<ResolveOptions>,
}
#[cfg(feature = "deserialize_bundler_options")]
fn deserialize_external<'de, D>(deserializer: D) -> Result<Option<IsExternal>, D::Error>
where
D: Deserializer<'de>,
{
let deserialized = Option::<Vec<String>>::deserialize(deserializer)?;
Ok(deserialized.map(IsExternal::from_vec))
}
#[cfg(feature = "deserialize_bundler_options")]
fn deserialize_addon<'de, D>(deserializer: D) -> Result<Option<AddonOutputOption>, D::Error>
where
D: Deserializer<'de>,
{
let deserialized = Option::<String>::deserialize(deserializer)?;
Ok(deserialized.map(|s| AddonOutputOption::String(Some(s))))
}