mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(cli): sfc style inject
This commit is contained in:
parent
8b2067af68
commit
bad666240e
@ -15,6 +15,11 @@ function trim(code: string) {
|
|||||||
return code.replace(/\/\/\n/g, '').trim();
|
return code.replace(/\/\/\n/g, '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSfcStylePath(filePath: string, ext: string, index: number) {
|
||||||
|
const number = index !== 0 ? `-${index + 1}` : '';
|
||||||
|
return replaceExt(filePath, `-sfc${number}.${ext}`);
|
||||||
|
}
|
||||||
|
|
||||||
// inject render fn to script
|
// inject render fn to script
|
||||||
function injectRender(script: string, render: string) {
|
function injectRender(script: string, render: string) {
|
||||||
script = trim(script);
|
script = trim(script);
|
||||||
@ -37,8 +42,7 @@ function injectStyle(
|
|||||||
if (styles.length) {
|
if (styles.length) {
|
||||||
const imports = styles
|
const imports = styles
|
||||||
.map((style, index) => {
|
.map((style, index) => {
|
||||||
const prefix = index !== 0 ? `-${index + 1}` : '';
|
const { base } = parse(getSfcStylePath(filePath, 'css', index));
|
||||||
const { base } = parse(replaceExt(filePath, `${prefix}.css`));
|
|
||||||
return `import './${base}';`;
|
return `import './${base}';`;
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
@ -90,9 +94,7 @@ export async function compileSfc(filePath: string) {
|
|||||||
// compile style part
|
// compile style part
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
styles.map((style, index: number) => {
|
styles.map((style, index: number) => {
|
||||||
const prefix = index !== 0 ? `-${index + 1}` : '';
|
const cssFilePath = getSfcStylePath(filePath, style.lang || 'css', index);
|
||||||
const ext = style.lang || 'css';
|
|
||||||
const cssFilePath = replaceExt(filePath, `-sfc${prefix}.${ext}`);
|
|
||||||
|
|
||||||
writeFileSync(cssFilePath, trim(style.content));
|
writeFileSync(cssFilePath, trim(style.content));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user