Skip to content

Commit a4a6db0

Browse files
committed
fix(api): ensure loaders.js returns a body if not required. fixes #47
1 parent 70f6f88 commit a4a6db0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

rjs-parse/src/build_config.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ impl RequireJsBuildConfig {
297297
)
298298
})
299299
.collect();
300-
items.join("\n")
300+
301+
if items.len() > 0 {
302+
items.join("\n")
303+
} else {
304+
include_str!("./js/no-loaders.js").to_string()
305+
}
301306
}
302307
///
303308
/// Walk the mixins fields and flatten to a simple Vec<String>

rjs-parse/src/js/no-loaders.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
*
3+
* You haven't configured any modules yet, so you don't
4+
* need this 'loaders.js' file.
5+
*
6+
* Once you configure some additional bundles this file
7+
* will be populated with some Javascript :)
8+
*
9+
*/

tests/api.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ fn test_config_json() {
4141

4242
#[test]
4343
fn test_loaders_js() {
44-
api_get(DEFAULT_ARGS.to_vec(), "/__bs/loaders.js", |result| {
45-
let (_sys, _url, res) = result.expect("api returned");
44+
let args = &[
45+
"config-gen",
46+
"http://example.com",
47+
];
48+
api_get(args.to_vec(), "/__bs/loaders.js", |result| {
49+
let (_sys, _url, mut res) = result.expect("api returned");
50+
let t = &res.text().expect("unwrap text response");
4651
let ct = &res
4752
.headers()
4853
.get(http::header::CONTENT_TYPE)
4954
.expect("has content-type");
5055
assert_eq!(ct.to_str().expect("header->str"), "application/javascript");
56+
assert!(t.len() > 0);
5157
});
5258
}
5359

0 commit comments

Comments
 (0)