11/* eslint-disable no-console */
22// eslint-disable-next-line import/no-unresolved
33import * as m from 'monaco-editor' ;
4- import { h , createApp } from 'vue' ;
4+ import { watchEffect } from 'vue' ;
55import { transform } from '@babel/core' ;
66import babelPluginJsx from '../../babel-plugin-jsx/src' ;
7+ import { initOptions , compilerOptions } from './options' ;
78import './index.css' ;
89
910declare global {
@@ -15,17 +16,6 @@ declare global {
1516
1617window . init = ( ) => {
1718 const { monaco } = window ;
18- createApp (
19- ( ) => h ( 'h1' , null , 'Vue JSX Explorer' ) ,
20- ) . mount ( '#header' ) ;
21-
22- // @ts -ignore
23- if ( module . hot ) {
24- // @ts -ignore
25- module . hot . accept ( '../../babel-plugin-jsx/src' , ( ) => {
26- compile ( ) ;
27- } ) ;
28- }
2919
3020 const sharedEditorOptions : m . editor . IStandaloneEditorConstructionOptions = {
3121 theme : 'vs-dark' ,
@@ -61,14 +51,15 @@ window.init = () => {
6151 ...sharedEditorOptions ,
6252 } ) ;
6353
64- const compile = ( ) => {
54+ const reCompile = ( ) => {
6555 const src = editor . getValue ( ) ;
66- localStorage . setItem ( 'state' , src ) ;
56+ const state = JSON . stringify ( compilerOptions ) ;
57+ localStorage . setItem ( 'state' , state ) ;
6758 window . location . hash = encodeURIComponent ( src ) ;
6859 console . clear ( ) ;
6960 transform ( src , {
7061 babelrc : false ,
71- plugins : [ [ babelPluginJsx , { transformOn : true , optimize : true } ] ] ,
62+ plugins : [ [ babelPluginJsx , compilerOptions ] ] ,
7263 ast : true ,
7364 } , ( err , result = { } ) => {
7465 const res = result ! ;
@@ -87,10 +78,11 @@ window.init = () => {
8778 output . layout ( ) ;
8879 } ) ;
8980
90- compile ( ) ;
81+ initOptions ( ) ;
82+ watchEffect ( reCompile ) ;
9183
9284 // update compile output when input changes
93- editor . onDidChangeModelContent ( debounce ( compile ) ) ;
85+ editor . onDidChangeModelContent ( debounce ( reCompile ) ) ;
9486} ;
9587
9688function debounce < T extends ( ...args : any [ ] ) => any > (
0 commit comments