Skip to content
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

feat: import path for global styles #28

Merged
merged 9 commits into from
Nov 13, 2024
9 changes: 9 additions & 0 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export async function sync(opts: SyncOptions) {
},
} as Config);

// Check for existing global styles (.css or .less) and set the import path
const globalStylesPath = path.join(cwd, 'src/global');
const styleExtensions = ['.css', '.less'];
const ext = styleExtensions.find((ext) =>
fs.existsSync(`${globalStylesPath}${ext}`),
);
const globalStyleImportPath = ext ? `import '../global${ext}';` : '';

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