mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
test: using esbuild instead of babel-jest (#10154)
* test: using esbuild instead of babel-jest * chore: update lock
This commit is contained in:
32
packages/vant-cli/cjs/jest.transformer.cjs
Normal file
32
packages/vant-cli/cjs/jest.transformer.cjs
Normal file
@@ -0,0 +1,32 @@
|
||||
const { transform: babelTransform } = require('@babel/core');
|
||||
const { transformSync: esbuildTransformSync } = require('esbuild');
|
||||
|
||||
const isJsxFile = (path) => /\.(j|t)sx$/.test(path);
|
||||
const isTsxFile = (path) => /\.tsx$/.test(path);
|
||||
|
||||
const transformJsx = (code, path) => {
|
||||
const babelResult = babelTransform(code, {
|
||||
filename: path,
|
||||
babelrc: false,
|
||||
presets: isTsxFile(path) ? ['@babel/preset-typescript'] : [],
|
||||
plugins: [['@vue/babel-plugin-jsx']],
|
||||
});
|
||||
return babelResult?.code || '';
|
||||
};
|
||||
|
||||
const transformScript = (code) =>
|
||||
esbuildTransformSync(code, {
|
||||
target: 'es2016',
|
||||
format: 'cjs',
|
||||
loader: 'ts',
|
||||
}).code;
|
||||
|
||||
module.exports = {
|
||||
canInstrument: true,
|
||||
process(code, path) {
|
||||
if (isJsxFile(path)) {
|
||||
code = transformJsx(code, path);
|
||||
}
|
||||
return transformScript(code);
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user