webpack_stats/v5/asset.rs
1/*
2 * Copyright [2022] [Kevin Velasco]
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::common::chunk::ChunkId;
18use crate::common::chunk::ChunkName;
19use std::borrow::Cow;
20use zerovec::ZeroVec;
21
22use crate::common::SizeBytes;
23use serde::Deserialize;
24
25// # Assets
26// (Link to webpack docs)[https://webpack.js.org/api/stats/#asset-objects]
27//
28// Each assets object represents an output file emitted from the compilation.
29// They all follow a similar structure:
30
31#[derive(Deserialize, Debug, Default)]
32#[serde(rename_all = "camelCase", default)]
33pub struct Asset<'a> {
34 /// Undocumented by webpack.
35 #[serde(borrow)]
36 pub r#type: Cow<'a, str>,
37 /// The `output` filename
38 #[serde(borrow)]
39 pub name: Cow<'a, str>,
40 /// The chunks this asset contains
41 pub chunk_names: Vec<ChunkName<'a>>,
42 /// Undocumented by webpack
43 #[serde(skip)]
44 pub chunk_id_hints: &'a [()],
45 /// The chunk IDs this asset contains
46 #[serde(borrow)]
47 pub chunks: ZeroVec<'a, ChunkId>,
48 /// Indicates whether or not the asset was compared with the same file on the output file system
49 pub compared_for_emit: bool,
50 /// The size of the file in bytes
51 pub size: SizeBytes,
52 pub info: AssetInfo<'a>,
53}
54
55#[derive(Deserialize, Debug, Default)]
56#[serde(rename_all = "camelCase", default)]
57pub struct AssetInfo<'a> {
58 /// A flag telling whether the asset can be long term cached (contains a hash)
59 pub immutable: bool,
60 /// The size in bytes, only becomes available after asset has been emitted
61 pub size: SizeBytes,
62 /// A flag telling whether the asset is only used for development and doesn't count towards user-facing assets
63 pub development: bool,
64 pub hot_module_replacement: bool,
65 #[serde(borrow)]
66 pub source_filename: Cow<'a, str>,
67 pub javascript_module: bool,
68 pub minimized: bool,
69}