From 256db3535ce9d2e321c421887066d2a263e36257 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Sun, 24 Dec 2023 15:08:27 -0800 Subject: [PATCH] Use IIFE output format for JS rather than ESM --- crates/mdbook-quiz/src/main.rs | 8 +++++--- js/packages/quiz-embed/vite.config.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/mdbook-quiz/src/main.rs b/crates/mdbook-quiz/src/main.rs index 82994fc..590c427 100644 --- a/crates/mdbook-quiz/src/main.rs +++ b/crates/mdbook-quiz/src/main.rs @@ -16,7 +16,7 @@ use uuid::Uuid; mdbook_preprocessor_utils::asset_generator!("../js/"); -const FRONTEND_ASSETS: [Asset; 2] = [make_asset!("quiz-embed.mjs"), make_asset!("style.css")]; +const FRONTEND_ASSETS: [Asset; 2] = [make_asset!("quiz-embed.iife.js"), make_asset!("style.css")]; #[cfg(feature = "rust-editor")] const RA_ASSETS: [Asset; 3] = [ @@ -29,7 +29,7 @@ const RA_ASSETS: [Asset; 0] = []; #[cfg(feature = "source-map")] const SOURCE_MAP_ASSETS: [Asset; 1] = [ - make_asset!("quiz-embed.mjs.map"), /*make_asset!("style.css.map")*/ + make_asset!("quiz-embed.iife.js.map"), /*make_asset!("style.css.map")*/ ]; #[cfg(not(feature = "source-map"))] const SOURCE_MAP_ASSETS: [Asset; 0] = []; @@ -295,7 +295,9 @@ mod test { let quiz_contents = fs::read_to_string(quiz_path)?; let quiz: Quiz = toml::from_str(&quiz_contents)?; - let Question::ShortAnswer(q) = &quiz.questions[0] else { panic!("Invalid quiz") }; + let Question::ShortAnswer(q) = &quiz.questions[0] else { + panic!("Invalid quiz") + }; assert!(q.0.id.is_some(), "ID not automatically inserted"); Ok(()) diff --git a/js/packages/quiz-embed/vite.config.ts b/js/packages/quiz-embed/vite.config.ts index 57752b1..32a8e00 100644 --- a/js/packages/quiz-embed/vite.config.ts +++ b/js/packages/quiz-embed/vite.config.ts @@ -33,7 +33,7 @@ export default defineConfig(({ mode }) => ({ lib: { entry: resolve(__dirname, "src/main.tsx"), name: "Quiz", - formats: ["es"], + formats: ["iife"], }, rollupOptions: { external: Object.keys(manifest.dependencies || {}),