refactor(jsx-explorer): replace @babel/core with @babel/standalone

This commit is contained in:
三咲智子 Kevin Deng 2024-09-07 05:04:05 +08:00
parent 455ae7182d
commit 4bd09577cc
No known key found for this signature in database
4 changed files with 31 additions and 26 deletions

View File

@ -9,14 +9,14 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@babel/core": "^7.25.2", "@babel/standalone": "^7.25.6",
"@vue/babel-plugin-jsx": "workspace:*", "@vue/babel-plugin-jsx": "workspace:*",
"assert": "^2.1.0", "assert": "^2.1.0",
"monaco-editor": "^0.51.0", "monaco-editor": "^0.51.0",
"pathe": "^1.1.2",
"vue": "^3.5.3" "vue": "^3.5.3"
}, },
"devDependencies": { "devDependencies": {
"@types/babel__standalone": "^7.1.7",
"@vitejs/plugin-vue-jsx": "^4.0.1", "@vitejs/plugin-vue-jsx": "^4.0.1",
"terser": "^5.31.6", "terser": "^5.31.6",
"unplugin-replace": "^0.3.3", "unplugin-replace": "^0.3.3",

View File

@ -1,6 +1,6 @@
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import { watchEffect } from 'vue'; import { watchEffect } from 'vue';
import { transform } from '@babel/core'; import { transform } from '@babel/standalone';
import babelPluginJsx from '@vue/babel-plugin-jsx'; import babelPluginJsx from '@vue/babel-plugin-jsx';
// @ts-expect-error missing types // @ts-expect-error missing types
import typescript from '@babel/plugin-syntax-typescript'; import typescript from '@babel/plugin-syntax-typescript';
@ -85,27 +85,21 @@ const App = defineComponent((props) => <div>Hello World</div>)`,
localStorage.setItem('state', state); localStorage.setItem('state', state);
window.location.hash = encodeURIComponent(src); window.location.hash = encodeURIComponent(src);
console.clear(); console.clear();
transform( try {
src, const res = transform(src, {
{
babelrc: false, babelrc: false,
plugins: [ plugins: [
[babelPluginJsx, { ...compilerOptions }], [babelPluginJsx, { ...compilerOptions }],
[typescript, { isTSX: true }], [typescript, { isTSX: true }],
], ],
ast: true, ast: true,
}, });
(err, result = {}) => { console.log('AST', res.ast!);
const res = result!; output.setValue(res.code!);
if (!err) { } catch (err: any) {
console.log('AST', res.ast!); console.error(err);
output.setValue(res.code!); output.setValue(err.message!);
} else { }
console.error(err);
output.setValue(err.message!);
}
}
);
}; };
// handle resize // handle resize

View File

@ -9,7 +9,6 @@ export default defineConfig({
resolve: { resolve: {
alias: { alias: {
'@vue/babel-plugin-jsx': '@vue/babel-plugin-jsx/src/index.ts', '@vue/babel-plugin-jsx': '@vue/babel-plugin-jsx/src/index.ts',
path: 'pathe',
}, },
}, },
plugins: [ plugins: [
@ -17,10 +16,6 @@ export default defineConfig({
Replace({ Replace({
values: { values: {
'process.env.BABEL_TYPES_8_BREAKING': 'false', '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; }',
}, },
}), }),
], ],

View File

@ -165,9 +165,9 @@ importers:
packages/jsx-explorer: packages/jsx-explorer:
dependencies: dependencies:
'@babel/core': '@babel/standalone':
specifier: ^7.25.2 specifier: ^7.25.6
version: 7.25.2 version: 7.25.6
'@vue/babel-plugin-jsx': '@vue/babel-plugin-jsx':
specifier: workspace:* specifier: workspace:*
version: link:../babel-plugin-jsx version: link:../babel-plugin-jsx
@ -184,6 +184,9 @@ importers:
specifier: ^3.5.3 specifier: ^3.5.3
version: 3.5.3(typescript@5.5.4) version: 3.5.3(typescript@5.5.4)
devDependencies: devDependencies:
'@types/babel__standalone':
specifier: ^7.1.7
version: 7.1.7
'@vitejs/plugin-vue-jsx': '@vitejs/plugin-vue-jsx':
specifier: ^4.0.1 specifier: ^4.0.1
version: 4.0.1(vite@5.4.3(@types/node@22.5.4)(terser@5.31.6))(vue@3.5.3(typescript@5.5.4)) version: 4.0.1(vite@5.4.3(@types/node@22.5.4)(terser@5.31.6))(vue@3.5.3(typescript@5.5.4))
@ -785,6 +788,10 @@ packages:
resolution: {integrity: sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==} resolution: {integrity: sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==}
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
'@babel/standalone@7.25.6':
resolution: {integrity: sha512-Kf2ZcZVqsKbtYhlA7sP0z5A3q5hmCVYMKMWRWNK/5OVwHIve3JY1djVRmIVAx8FMueLIfZGKQDIILK2w8zO4mg==}
engines: {node: '>=6.9.0'}
'@babel/template@7.25.0': '@babel/template@7.25.0':
resolution: {integrity: sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==} resolution: {integrity: sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==}
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
@ -1289,6 +1296,9 @@ packages:
'@types/babel__helper-plugin-utils@7.10.3': '@types/babel__helper-plugin-utils@7.10.3':
resolution: {integrity: sha512-FcLBBPXInqKfULB2nvOBskQPcnSMZ0s1Y2q76u9H1NPPWaLcTeq38xBeKfF/RBUECK333qeaqRdYoPSwW7rTNQ==} resolution: {integrity: sha512-FcLBBPXInqKfULB2nvOBskQPcnSMZ0s1Y2q76u9H1NPPWaLcTeq38xBeKfF/RBUECK333qeaqRdYoPSwW7rTNQ==}
'@types/babel__standalone@7.1.7':
resolution: {integrity: sha512-4RUJX9nWrP/emaZDzxo/+RYW8zzLJTXWJyp2k78HufG459HCz754hhmSymt3VFOU6/Wy+IZqfPvToHfLuGOr7w==}
'@types/babel__template@7.4.4': '@types/babel__template@7.4.4':
resolution: {integrity: sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==} resolution: {integrity: sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==}
@ -3792,6 +3802,8 @@ snapshots:
dependencies: dependencies:
regenerator-runtime: 0.14.1 regenerator-runtime: 0.14.1
'@babel/standalone@7.25.6': {}
'@babel/template@7.25.0': '@babel/template@7.25.0':
dependencies: dependencies:
'@babel/code-frame': 7.24.7 '@babel/code-frame': 7.24.7
@ -4147,6 +4159,10 @@ snapshots:
dependencies: dependencies:
'@types/babel__core': 7.20.5 '@types/babel__core': 7.20.5
'@types/babel__standalone@7.1.7':
dependencies:
'@types/babel__core': 7.20.5
'@types/babel__template@7.4.4': '@types/babel__template@7.4.4':
dependencies: dependencies:
'@babel/parser': 7.25.6 '@babel/parser': 7.25.6