-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize shadow DOM component css imports (50%)
- Loading branch information
Showing
20 changed files
with
3,875 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# base url for yao app | ||
BASE="yao" | ||
BASE="__yao_admin_root" | ||
|
||
# umi | ||
DID_YOU_KNOW="none" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Generate the Components sss files, for the shadow dom dynamic import | ||
*/ | ||
|
||
import child_process from 'child_process' | ||
import fs, { appendFile } from 'fs' | ||
import path from 'path' | ||
import { ExportComponent, ExportComponents } from '../components/exports' | ||
|
||
const cwd = process.cwd() | ||
const target_root = path.join(cwd, `/public/components`) | ||
|
||
// Generate the sss files for the components | ||
const compile = (name: string, component: ExportComponent) => { | ||
const output = path.join(target_root, `${name}`) | ||
const input = path.join(cwd, `__main.less`) | ||
|
||
// Generate the main.less file import the component styles | ||
const imports: string[] = [] | ||
component.styles.forEach((style, index) => { | ||
if (style.startsWith('@/')) { | ||
imports.push(`@import url('/__yao_admin_root/${style.substring(2, style.length)}');`) | ||
return | ||
} | ||
// fs.appendFileSync(input, `@import ".${style}";\n`) | ||
const lessFile = path.join(cwd, style) | ||
const targetName = `chunk.${index}.css` | ||
const targetPath = path.join(output, targetName) | ||
imports.push(`@import url('/__yao_admin_root/components/${name}/${targetName}');`) | ||
|
||
// Compile the less file | ||
child_process.execSync(`lessc ${lessFile} ${targetPath}`) | ||
|
||
// Replace :global with :host | ||
const content = fs.readFileSync(targetPath, 'utf8').replace(/:global/g, '') | ||
fs.writeFileSync(targetPath, content) | ||
}) | ||
|
||
// Create the index.sss file | ||
const indexFile = path.join(output, `index.sss`) | ||
fs.writeFileSync(indexFile, imports.join('\n')) | ||
} | ||
|
||
// Generate the sss files for the components | ||
Object.entries(ExportComponents).forEach(([name, component]) => compile(name, component)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
._local { | ||
.xgen-edit-upload { | ||
padding-bottom: 0; | ||
|
||
&.image { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* The components for shadow dom and dynamic import | ||
*/ | ||
export const ExportComponents: Record<string, ExportComponent> = { | ||
'edit/Upload': { | ||
styles: [ | ||
'/components/edit/Upload/index.less', | ||
'/components/edit/Upload/components/Loader.less', | ||
'/components/edit/Upload/components/Audio.less', | ||
'/components/edit/Upload/components/Image.less', | ||
'/components/edit/Upload/components/Video.less', | ||
'@/assets/css/vidstack/theme.css', | ||
'@/assets/css/vidstack/layouts/audio.css', | ||
'@/assets/css/vidstack/layouts/video.css' | ||
] | ||
} | ||
} | ||
|
||
export interface ExportComponent { | ||
styles: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.