-
Notifications
You must be signed in to change notification settings - Fork 298
fix: 构建全量 css 文件 #2847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: 构建全量 css 文件 #2847
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -173,6 +173,32 @@ async function buildUMD(p) { | |
| } | ||
|
|
||
| async function buildAllCSS() { | ||
| // 拷贝styles | ||
| async function copyStyles() { | ||
| await copy( | ||
| resolve(__dirname, '../src/styles'), | ||
| resolve(__dirname, '../dist/styles') | ||
| ) | ||
|
|
||
| const content = [ | ||
| `@import './styles/theme-default.scss';`, | ||
| `@import './styles/variables.scss';`, | ||
| `@import './styles/mixins/index.scss';`, | ||
| `@import './styles/animation/index.scss';`, | ||
| ] | ||
| const projectID = process.env.VITE_APP_PROJECT_ID | ||
| if (projectID) { | ||
| content[1] = `@import '../variables-${projectID}.scss';` | ||
| } | ||
| const scssFiles = await glob(['dist/es/packages/**/*.scss']) | ||
| scssFiles.forEach((file) => { | ||
| content.push( | ||
| `@import '${relativeFilePath('/dist/style.scss', '/' + file)}';` | ||
| ) | ||
| }) | ||
| dest('dist/style.scss', content.join('\n')) | ||
| } | ||
| await copyStyles() | ||
|
Comment on lines
+177
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议避免重复定义函数 在 应用以下差异来修复此问题: -async function buildAllCSS() {
- // 拷贝styles
- async function copyStyles() {
- // 函数内容
- }
- await copyStyles()
- // 其他代码
-}
+async function buildAllCSS() {
+ await copyStyles()
+ // 其他代码
+}Also applies to: 241-250 |
||
| await vite.build({ | ||
| logLevel: 'error', | ||
| resolve: { | ||
|
|
@@ -181,7 +207,7 @@ async function buildAllCSS() { | |
| build: { | ||
| emptyOutDir: false, | ||
| lib: { | ||
| entry: './dist/styles/themes/default.scss', | ||
| entry: './dist/style.scss', | ||
| formats: ['es'], | ||
| name: 'style', | ||
| fileName: 'style', | ||
|
|
@@ -190,6 +216,29 @@ async function buildAllCSS() { | |
| }) | ||
| } | ||
|
|
||
| async function buildThemeCSS() { | ||
| await vite.build({ | ||
| logLevel: 'error', | ||
| resolve: { | ||
| alias: [{ find: '@', replacement: resolve(__dirname, '../src') }], | ||
| }, | ||
| build: { | ||
| emptyOutDir: false, | ||
| rollupOptions: { | ||
| output: [ | ||
| { | ||
| dir: 'dist/styles/themes', | ||
| assetFileNames: 'default.css', | ||
| }, | ||
| ], | ||
| }, | ||
| lib: { | ||
| entry: './dist/styles/themes/default.scss', | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // 拷贝styles | ||
| async function copyStyles() { | ||
| await copy( | ||
|
|
@@ -218,6 +267,7 @@ async function buildCSS(p) { | |
| const cssFiles = await glob(['src/packages/**/*.scss'], { | ||
| ignore: ['src/packages/**/demo.scss'], | ||
| }) | ||
|
|
||
| const variables = await readFile( | ||
| join(__dirname, '../src/styles/variables.scss') | ||
| ) | ||
|
|
@@ -296,26 +346,6 @@ async function buildCSS(p) { | |
| } | ||
| } | ||
|
|
||
| // async function exportProps() { | ||
| // const types = [] | ||
| // const a = await readFile(join(__dirname, '../src/config.json')) | ||
| // const componentsConfig = JSON.parse(a.toString()) | ||
| // componentsConfig.nav.forEach((item) => { | ||
| // item.packages.forEach((element) => { | ||
| // const { name, show, exportEmpty } = element | ||
| // if (show || exportEmpty) { | ||
| // const lowerName = name.toLowerCase() | ||
| // if (lowerName === 'icon') return | ||
| // types.push(`export * from './${lowerName}/index'`) | ||
| // } | ||
| // }) | ||
| // }) | ||
| // await appendFile( | ||
| // join(__dirname, '../dist/es/packages/nutui.react.build.d.ts'), | ||
| // types.join('\n') | ||
| // ) | ||
| // } | ||
|
|
||
| console.time('clean dist') | ||
| await deleteAsync('dist') | ||
| console.timeEnd('clean dist') | ||
|
|
@@ -346,6 +376,10 @@ console.time('Build All CSS') | |
| await buildAllCSS() | ||
| console.timeEnd('Build All CSS') | ||
|
|
||
| console.time('Build Theme CSS') | ||
| await buildThemeCSS() | ||
| console.timeEnd('Build Theme CSS') | ||
|
|
||
| console.time('Build Declaration') | ||
| await buildDeclaration() | ||
| console.timeEnd('Build Declaration') | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议避免重复定义函数
copyStyles在
buildAllCSS函数内部和全局范围内都定义了名为copyStyles的函数,这可能导致混淆和意外的行为。建议将copyStyles函数移到全局范围,或者在buildAllCSS内部使用不同的函数名称。应用以下差异来修复此问题:
Also applies to: 281-291