mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-11 01:38:56 +08:00
27 lines
817 B
TypeScript
27 lines
817 B
TypeScript
import { transformAsync } from '@babel/core';
|
|
import { readFileSync, removeSync, outputFileSync } from 'fs-extra';
|
|
import { replaceExt } from '../common';
|
|
import { replaceCssImportExt } from '../common/css';
|
|
import { replaceScriptImportExt } from './get-deps';
|
|
|
|
export function compileJs(filePath: string): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
let code = readFileSync(filePath, 'utf-8');
|
|
|
|
code = replaceCssImportExt(code);
|
|
code = replaceScriptImportExt(code, '.vue', '');
|
|
|
|
transformAsync(code, { filename: filePath })
|
|
.then((result) => {
|
|
if (result) {
|
|
const jsFilePath = replaceExt(filePath, '.js');
|
|
|
|
removeSync(filePath);
|
|
outputFileSync(jsFilePath, result.code);
|
|
resolve();
|
|
}
|
|
})
|
|
.catch(reject);
|
|
});
|
|
}
|