mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(cli): failed to compile ts in sfc
This commit is contained in:
parent
32b0654c58
commit
4433779c2e
@ -62,7 +62,6 @@ export function parseSfc(filename: string) {
|
|||||||
export async function compileSfc(filePath: string): Promise<any> {
|
export async function compileSfc(filePath: string): Promise<any> {
|
||||||
const tasks = [remove(filePath)];
|
const tasks = [remove(filePath)];
|
||||||
const source = readFileSync(filePath, 'utf-8');
|
const source = readFileSync(filePath, 'utf-8');
|
||||||
const jsFilePath = replaceExt(filePath, '.js');
|
|
||||||
const descriptor = parseSfc(filePath);
|
const descriptor = parseSfc(filePath);
|
||||||
const { template, styles } = descriptor;
|
const { template, styles } = descriptor;
|
||||||
|
|
||||||
@ -71,6 +70,9 @@ export async function compileSfc(filePath: string): Promise<any> {
|
|||||||
|
|
||||||
// compile js part
|
// compile js part
|
||||||
if (descriptor.script) {
|
if (descriptor.script) {
|
||||||
|
const lang = descriptor.script.lang || 'js';
|
||||||
|
const scriptFilePath = replaceExt(filePath, `.${lang}`);
|
||||||
|
|
||||||
tasks.push(
|
tasks.push(
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
let script = descriptor.script!.content;
|
let script = descriptor.script!.content;
|
||||||
@ -89,8 +91,8 @@ export async function compileSfc(filePath: string): Promise<any> {
|
|||||||
script = injectScopeId(script, scopeId);
|
script = injectScopeId(script, scopeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeFileSync(jsFilePath, script);
|
writeFileSync(scriptFilePath, script);
|
||||||
compileJs(jsFilePath).then(resolve).catch(reject);
|
compileJs(scriptFilePath).then(resolve).catch(reject);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user