pub fn maybe_prettyprint<G>(
script_name: &str,
source_str: &mut String,
generate_file: G,
)Expand description
Convenience function to create a sourcemap for the prettyprinted version of the file (if it needs prettyprinting), generate a URL for it and append that URL to the file text so it gets used.
The generate_file closure takes a file name and file text and returns a URL which can
be used to load that file. This URL is injected into source_str.
Example:
let mut generated = "//PRETTYPRINT\nfunction x(a){return a;}".to_string();
prettify_js::maybe_prettyprint("demo.js", &mut generated,
|name, text| {
assert_eq!(name, "demo.js.sourcemap");
let url = "https://example.com/demo.js.sourcemap".to_string();
println!("Serve {} with contents {}", &url, text);
url
});
assert_eq!(generated, "//PRETTYPRINT\nfunction x(a){return a;}\n//# sourceMappingURL=https://example.com/demo.js.sourcemap");