bertui 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/client/compiler.js +15 -10
package/package.json
CHANGED
package/src/client/compiler.js
CHANGED
|
@@ -111,7 +111,7 @@ async function generateRouter(routes, outDir, root) {
|
|
|
111
111
|
return ` { path: '${route.route}', component: ${componentName}, type: '${route.type}' }`;
|
|
112
112
|
}).join(',\n');
|
|
113
113
|
|
|
114
|
-
const routerComponentCode = `import { useState, useEffect, createContext, useContext
|
|
114
|
+
const routerComponentCode = `import React, { useState, useEffect, createContext, useContext } from 'react';
|
|
115
115
|
|
|
116
116
|
const RouterContext = createContext(null);
|
|
117
117
|
|
|
@@ -185,10 +185,10 @@ export function Router({ routes }) {
|
|
|
185
185
|
|
|
186
186
|
const Component = currentRoute?.component;
|
|
187
187
|
|
|
188
|
-
return createElement(
|
|
188
|
+
return React.createElement(
|
|
189
189
|
RouterContext.Provider,
|
|
190
190
|
{ value: routerValue },
|
|
191
|
-
Component ? createElement(Component, { params }) : createElement(NotFound, null)
|
|
191
|
+
Component ? React.createElement(Component, { params }) : React.createElement(NotFound, null)
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -200,11 +200,11 @@ export function Link({ to, children, ...props }) {
|
|
|
200
200
|
navigate(to);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
return createElement('a', { href: to, onClick: handleClick, ...props }, children);
|
|
203
|
+
return React.createElement('a', { href: to, onClick: handleClick, ...props }, children);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
function NotFound() {
|
|
207
|
-
return createElement(
|
|
207
|
+
return React.createElement(
|
|
208
208
|
'div',
|
|
209
209
|
{
|
|
210
210
|
style: {
|
|
@@ -216,9 +216,9 @@ function NotFound() {
|
|
|
216
216
|
fontFamily: 'system-ui'
|
|
217
217
|
}
|
|
218
218
|
},
|
|
219
|
-
createElement('h1', { style: { fontSize: '6rem', margin: 0 } }, '404'),
|
|
220
|
-
createElement('p', { style: { fontSize: '1.5rem', color: '#666' } }, 'Page not found'),
|
|
221
|
-
createElement('a', {
|
|
219
|
+
React.createElement('h1', { style: { fontSize: '6rem', margin: 0 } }, '404'),
|
|
220
|
+
React.createElement('p', { style: { fontSize: '1.5rem', color: '#666' } }, 'Page not found'),
|
|
221
|
+
React.createElement('a', {
|
|
222
222
|
href: '/',
|
|
223
223
|
style: { color: '#10b981', textDecoration: 'none', fontSize: '1.2rem' }
|
|
224
224
|
}, 'Go home')
|
|
@@ -290,13 +290,18 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
290
290
|
loader,
|
|
291
291
|
tsconfig: {
|
|
292
292
|
compilerOptions: {
|
|
293
|
-
jsx: 'react
|
|
294
|
-
|
|
293
|
+
jsx: 'react',
|
|
294
|
+
jsxFactory: 'React.createElement',
|
|
295
|
+
jsxFragmentFactory: 'React.Fragment'
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
298
|
});
|
|
298
299
|
let compiled = await transpiler.transform(code);
|
|
299
300
|
|
|
301
|
+
if (!compiled.includes('import React') && (compiled.includes('React.createElement') || compiled.includes('React.Fragment'))) {
|
|
302
|
+
compiled = `import React from 'react';\n${compiled}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
300
305
|
compiled = fixRelativeImports(compiled);
|
|
301
306
|
|
|
302
307
|
const outFilename = filename.replace(/\.(jsx|tsx|ts)$/, '.js');
|