Skip to content

Commit

Permalink
Use IIFE output format for JS rather than ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Dec 24, 2023
1 parent f792a05 commit 256db35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions crates/mdbook-quiz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand All @@ -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] = [];
Expand Down Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion js/packages/quiz-embed/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}),
Expand Down

0 comments on commit 256db35

Please sign in to comment.