Skip to content

Commit

Permalink
refactor(jsx-explorer): replace @babel/core with @babel/standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Sep 6, 2024
1 parent 455ae71 commit 4bd0957
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/jsx-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"preview": "vite preview"
},
"dependencies": {
"@babel/core": "^7.25.2",
"@babel/standalone": "^7.25.6",
"@vue/babel-plugin-jsx": "workspace:*",
"assert": "^2.1.0",
"monaco-editor": "^0.51.0",
"pathe": "^1.1.2",
"vue": "^3.5.3"
},
"devDependencies": {
"@types/babel__standalone": "^7.1.7",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"terser": "^5.31.6",
"unplugin-replace": "^0.3.3",
Expand Down
26 changes: 10 additions & 16 deletions packages/jsx-explorer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as monaco from 'monaco-editor';
import { watchEffect } from 'vue';
import { transform } from '@babel/core';
import { transform } from '@babel/standalone';
import babelPluginJsx from '@vue/babel-plugin-jsx';
// @ts-expect-error missing types
import typescript from '@babel/plugin-syntax-typescript';
Expand Down Expand Up @@ -85,27 +85,21 @@ const App = defineComponent((props) => <div>Hello World</div>)`,
localStorage.setItem('state', state);
window.location.hash = encodeURIComponent(src);
console.clear();
transform(
src,
{
try {
const res = transform(src, {
babelrc: false,
plugins: [
[babelPluginJsx, { ...compilerOptions }],
[typescript, { isTSX: true }],
],
ast: true,
},
(err, result = {}) => {
const res = result!;
if (!err) {
console.log('AST', res.ast!);
output.setValue(res.code!);
} else {
console.error(err);
output.setValue(err.message!);
}
}
);
});
console.log('AST', res.ast!);
output.setValue(res.code!);
} catch (err: any) {
console.error(err);
output.setValue(err.message!);
}
};

// handle resize
Expand Down
5 changes: 0 additions & 5 deletions packages/jsx-explorer/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ export default defineConfig({
resolve: {
alias: {
'@vue/babel-plugin-jsx': '@vue/babel-plugin-jsx/src/index.ts',
path: 'pathe',
},
},
plugins: [
VueJSX(),
Replace({
values: {
'process.env.BABEL_TYPES_8_BREAKING': 'false',
'process.env.BABEL_ENV': '"development"',
'process.env.NODE_NDEBUG': 'true',
'process.env.NODE_DEBUG': 'false',
'Buffer.isBuffer': 'function isBuffer() { return false; }',
},
}),
],
Expand Down
22 changes: 19 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4bd0957

Please sign in to comment.