Skip to content

Commit

Permalink
fix(cli ui): 统一给每个包增加另一个style入口 方便babel-import-plugin解析
Browse files Browse the repository at this point in the history
affects: @varlet/cli, @varlet/ui
  • Loading branch information
haoziqaq committed Nov 27, 2020
1 parent 77b4174 commit cd1ef49
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/varlet-cli/src/compiler/compileCJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { CJS_DIR, SRC_DIR } from '../shared/constant'
import { getComponentNames, getExportDirNames, isDir } from '../shared/fsUtils'
import { compileComponent } from './compileComponent'
import { compileLibraryEntry } from './compileScript'
import { buildStyleEntry } from './compileStyle'

export async function compileCJS() {
await copy(SRC_DIR, CJS_DIR)
const cjsDir: string[] = await readdir(CJS_DIR)
await Promise.all(
cjsDir.map((filename: string) => {
const path: string = resolve(CJS_DIR, filename)
return isDir(path) ? compileComponent(path, 'cjs') : null
isDir(path) && buildStyleEntry(path)
return isDir(path) ? compileComponent(path) : null
})
)
compileLibraryEntry(CJS_DIR, await getComponentNames(), await getExportDirNames(), 'cjs')
Expand Down
6 changes: 3 additions & 3 deletions packages/varlet-cli/src/compiler/compileComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { resolve } from 'path'
import { compileScriptFile } from './compileScript'
import { compileLess } from './compileStyle'

export async function compileComponent(path: string, modules: string | boolean = false) {
const dirs = await readdir(path)
export async function compileComponent(dir: string, modules: string | boolean = false) {
const dirs = await readdir(dir)
await Promise.all(
dirs.map((filename) => {
const filePath = resolve(path, filename)
const filePath = resolve(dir, filename)
;[TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(filePath)
return compileFile(filePath, modules)
})
Expand Down
3 changes: 3 additions & 0 deletions packages/varlet-cli/src/compiler/compileES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { ES_DIR, SRC_DIR } from '../shared/constant'
import { getComponentNames, getExportDirNames, isDir } from '../shared/fsUtils'
import { compileComponent } from './compileComponent'
import { compileLibraryEntry } from './compileScript'
import { buildStyleEntry } from './compileStyle'

export async function compileES() {
await copy(SRC_DIR, ES_DIR)
const esDir: string[] = await readdir(ES_DIR)

await Promise.all(
esDir.map((filename: string) => {
const path: string = resolve(ES_DIR, filename)
isDir(path) && buildStyleEntry(path)
return isDir(path) ? compileComponent(path) : null
})
)
Expand Down
8 changes: 8 additions & 0 deletions packages/varlet-cli/src/compiler/compileStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export async function compileLess(path: string) {
writeFileSync(replaceExt(path, '.css'), clearEmptyLine(css), 'utf-8')
}

export function buildStyleEntry(dir: string) {
const styleDir: string = resolve(dir, './style')
const styleIndex: string = resolve(dir, './style/index.js')

!pathExistsSync(styleDir) && mkdirSync(styleDir)
!pathExistsSync(styleIndex) && writeFileSync(styleIndex, '', 'utf-8')
}

export function emitStyleEntry(path: string, modules: string | boolean = false) {
const { ext, dir, base } = parse(path)
const styleDir: string = resolve(dir, './style')
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/skeleton/Skeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
<div
class="varlet-skeleton__row"
v-for="(r, index) in row"
v-for="(r, index) in Array.from({ length: row - 1 })"
:key="r"
:style="{ width: rowWidth[index] }"
>
Expand Down

0 comments on commit cd1ef49

Please sign in to comment.