Skip to content

Commit

Permalink
feat: import path for global styles (#28)
Browse files Browse the repository at this point in the history
* feat:import path for global styles

* fix:sync format

* feat:add overrides file to write

* feat:add overrides file to write

* feat:add overrides file to write

feat:add overrides file to write

* fix:remove overrides import temporarily, pending further discussion

* fix:sync format

* Update .changeset/stupid-tomatoes-work.md

---------

Co-authored-by: chencheng (云谦) <[email protected]>
  • Loading branch information
iamwangqing and sorrycc authored Nov 13, 2024
1 parent 3f41d9a commit 599a505
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-tomatoes-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@umijs/tnf': patch
---

Support conventional src/global.{less,css} as global style
12 changes: 12 additions & 0 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ export async function sync(opts: SyncOptions) {
},
} as Config);

// Check for existing style files (.css or .less) and set import paths
const supportedExtensions = ['.css', '.less'];
function getStyleImportPath(basePath) {
const ext = supportedExtensions.find((ext) =>
fs.existsSync(path.join(basePath + ext)),
);
return ext ? `import '${basePath}${ext}';` : '';
}
const globalStylePath = path.join(cwd, 'src/global');
const globalStyleImportPath = getStyleImportPath(globalStylePath);

// tailwindcss
let tailwindcssPath: string | undefined;
if (config?.tailwindcss && !opts.runAgain) {
Expand All @@ -70,6 +81,7 @@ import {
createRouter,
} from '@umijs/tnf/router';
import { routeTree } from './routeTree.gen';
${globalStyleImportPath}
${tailwindcssPath ? `import '${tailwindcssPath}'` : ''}
const router = createRouter({
routeTree,
Expand Down

0 comments on commit 599a505

Please sign in to comment.