mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 08:37:23 +00:00
refactor(@vant/cli): migrate to ESM package
This commit is contained in:
26
packages/vant-cli/cjs/babel-preset-vue-ts.cjs
Normal file
26
packages/vant-cli/cjs/babel-preset-vue-ts.cjs
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @babel/preset-typescript 不支持编译 Vue 文件中的 ts 代码
|
||||
* 通过手动添加 @babel/plugin-transform-typescript 的方式来解决这个问题
|
||||
* see: https://github.com/babel/babel-loader/pull/738
|
||||
*/
|
||||
|
||||
const { readFileSync } = require('fs');
|
||||
const { declare } = require('@babel/helper-plugin-utils');
|
||||
|
||||
module.exports = declare(() => ({
|
||||
overrides: [
|
||||
{
|
||||
test: (filePath) => {
|
||||
if (/\.vue$/.test(filePath)) {
|
||||
const template = readFileSync(filePath, { encoding: 'utf8' });
|
||||
return (
|
||||
template.includes('lang="ts"') || template.includes("lang='ts'")
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
plugins: [require('@babel/plugin-transform-typescript')],
|
||||
},
|
||||
],
|
||||
}));
|
Reference in New Issue
Block a user