main.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // This test checks the CLI optimizes assets correctly without breaking them
  2. use dioxus::prelude::*;
  3. const MONACO_FOLDER: Asset = asset!("/monaco-editor-0.52.2/package/min/vs");
  4. const SOME_IMAGE: Asset = asset!("/images/toasts.png", ImageAssetOptions::new().with_avif());
  5. fn main() {
  6. dioxus::launch(App);
  7. }
  8. #[component]
  9. fn App() -> Element {
  10. let script = format!("(() => {{
  11. require.config({{ paths: {{ vs: '{MONACO_FOLDER}' }} }});
  12. require(['vs/editor/editor.main'], () => {{
  13. var model = monaco.editor.createModel('fn main() {{\\n\\tprintln!(\\\"hi\\\")\\n}}', 'rust');
  14. var editor = monaco.editor.create(document.getElementById('editor'));
  15. editor.setModel(model);
  16. }})
  17. }})()");
  18. rsx! {
  19. div {
  20. id: "editor",
  21. width: "100vw",
  22. height: "100vw",
  23. }
  24. // Monaco script
  25. script {
  26. src: "{MONACO_FOLDER}/loader.js",
  27. "onload": script
  28. }
  29. img {
  30. src: "{SOME_IMAGE}"
  31. }
  32. }
  33. }