Skip to content

Commit 4bd0957

Browse files
committed
refactor(jsx-explorer): replace @babel/core with @babel/standalone
1 parent 455ae71 commit 4bd0957

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

packages/jsx-explorer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12-
"@babel/core": "^7.25.2",
12+
"@babel/standalone": "^7.25.6",
1313
"@vue/babel-plugin-jsx": "workspace:*",
1414
"assert": "^2.1.0",
1515
"monaco-editor": "^0.51.0",
16-
"pathe": "^1.1.2",
1716
"vue": "^3.5.3"
1817
},
1918
"devDependencies": {
19+
"@types/babel__standalone": "^7.1.7",
2020
"@vitejs/plugin-vue-jsx": "^4.0.1",
2121
"terser": "^5.31.6",
2222
"unplugin-replace": "^0.3.3",

packages/jsx-explorer/src/index.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as monaco from 'monaco-editor';
22
import { watchEffect } from 'vue';
3-
import { transform } from '@babel/core';
3+
import { transform } from '@babel/standalone';
44
import babelPluginJsx from '@vue/babel-plugin-jsx';
55
// @ts-expect-error missing types
66
import typescript from '@babel/plugin-syntax-typescript';
@@ -85,27 +85,21 @@ const App = defineComponent((props) => <div>Hello World</div>)`,
8585
localStorage.setItem('state', state);
8686
window.location.hash = encodeURIComponent(src);
8787
console.clear();
88-
transform(
89-
src,
90-
{
88+
try {
89+
const res = transform(src, {
9190
babelrc: false,
9291
plugins: [
9392
[babelPluginJsx, { ...compilerOptions }],
9493
[typescript, { isTSX: true }],
9594
],
9695
ast: true,
97-
},
98-
(err, result = {}) => {
99-
const res = result!;
100-
if (!err) {
101-
console.log('AST', res.ast!);
102-
output.setValue(res.code!);
103-
} else {
104-
console.error(err);
105-
output.setValue(err.message!);
106-
}
107-
}
108-
);
96+
});
97+
console.log('AST', res.ast!);
98+
output.setValue(res.code!);
99+
} catch (err: any) {
100+
console.error(err);
101+
output.setValue(err.message!);
102+
}
109103
};
110104

111105
// handle resize

packages/jsx-explorer/vite.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ export default defineConfig({
99
resolve: {
1010
alias: {
1111
'@vue/babel-plugin-jsx': '@vue/babel-plugin-jsx/src/index.ts',
12-
path: 'pathe',
1312
},
1413
},
1514
plugins: [
1615
VueJSX(),
1716
Replace({
1817
values: {
1918
'process.env.BABEL_TYPES_8_BREAKING': 'false',
20-
'process.env.BABEL_ENV': '"development"',
21-
'process.env.NODE_NDEBUG': 'true',
22-
'process.env.NODE_DEBUG': 'false',
23-
'Buffer.isBuffer': 'function isBuffer() { return false; }',
2419
},
2520
}),
2621
],

pnpm-lock.yaml

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)