local font not working on nextjs , antd on ConfigProvider
local font not working on nextjs , antd on ConfigProvider
transpilePackages array in your next.config.js file:transpilePackages configuration might also solve certain problems. The behavior seems to vary depending on the specific versions of Next.js and Ant Design being used.public directory of your Next.js project so they can be served as static assets.public/fonts/ directory of your Next.js project_app.tsxtranspilePackages array in your next.config.js file as mentioned in our previous conversation to ensure proper styling with Ant Design in Next.js.@font-face declaration. The correct format specifier for TTF files is indeed 'truetype' and not 'ttf':format() value needs to match the standardized format name rather than the file extension.transpilePackagestranspilePackagestranspilePackagesnext.config.jsnext.config.jspublic/fonts/_app.tsx@font-face'truetype''ttf'format()/** @type {import('next').NextConfig} */
module.exports = {
transpilePackages: [
"@refinedev/antd",
"@refinedev/inferencer",
"antd",
"@ant-design/icons",
"@ant-design/pro-components",
"@ant-design/pro-layout",
"@ant-design/pro-utils",
"@ant-design/pro-provider"
],
};/* In your global CSS file (e.g., styles/globals.css) */
@font-face {
font-family: 'YourLocalFont';
src: url('/fonts/your-font-file.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-display: swap;
}@font-face {
font-family: 'YourLocalFont';
src: url('/fonts/your-font-file.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-display: swap;
}import { ConfigProvider } from "antd";
import { RefineThemes } from "@refinedev/antd";
// Create a custom theme with your font family
const customTheme = {
...RefineThemes.Blue,
token: {
...RefineThemes.Blue.token,
fontFamily: "YourLocalFont, sans-serif"
}
};
// In your _app.tsx
<ConfigProvider theme={customTheme}>
{/* Your app components */}
</ConfigProvider>const customTheme = {
...RefineThemes.Blue,
token: {
...RefineThemes.Blue.token,
fontFamily: "YourLocalFont, sans-serif"
}
};
<ConfigProvider theme={customTheme}>
{/* Your app components */}
</ConfigProvider><ConfigProvider theme={{
...RefineThemes.Blue,
token: {
...RefineThemes.Blue.token,
fontFamily: "YourLocalFont, sans-serif"
}
}}>