mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 19:06:36 +08:00
25 lines
708 B
TypeScript
25 lines
708 B
TypeScript
import { transformAsync } from '@babel/core';
|
|
import { readFileSync, removeSync, outputFileSync } from 'fs-extra';
|
|
import { replaceExt } from '../common';
|
|
import { replaceCssImport } from '../common/css';
|
|
|
|
export function compileJs(filePath: string): Promise<undefined> {
|
|
return new Promise((resolve, reject) => {
|
|
let code = readFileSync(filePath, 'utf-8');
|
|
|
|
code = replaceCssImport(code);
|
|
|
|
transformAsync(code, { filename: filePath })
|
|
.then(result => {
|
|
if (result) {
|
|
const jsFilePath = replaceExt(filePath, '.js');
|
|
|
|
removeSync(filePath);
|
|
outputFileSync(jsFilePath, result.code);
|
|
resolve();
|
|
}
|
|
})
|
|
.catch(reject);
|
|
});
|
|
}
|