Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IIFE output format for JS rather than ESM #41

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/mdbook-quiz/src/main.rs
Original file line number Diff line number Diff line change
@@ -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(())
2 changes: 1 addition & 1 deletion js/packages/quiz-embed/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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 || {}),