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

style is broken on build but works on dev env #103

Open
shereen-fathy opened this issue Jan 12, 2022 · 8 comments
Open

style is broken on build but works on dev env #103

shereen-fathy opened this issue Jan 12, 2022 · 8 comments

Comments

@shereen-fathy
Copy link

shereen-fathy commented Jan 12, 2022

Hi there I'm trying to use this plugin in my project
I'm using

1. "next": "^10.0.5"
2. "antd": "^4.16.0"
3. "next-plugin-antd-less": "^1.8.0"
4. "less": "^4.1.2"

and here is my next config file

const withPlugins = require("next-compose-plugins");
const { getThemeVariables } = require("antd/dist/theme");
const lessToJS = require("less-vars-to-js");
const fs = require("fs");
const path = require("path");

// antd custom variables
const themeVariables = lessToJS(
  fs.readFileSync(
    path.resolve(__dirname, "./styles/antd-variables.less"),
    "utf8"
  )
);
const antdLessConfig = {
  modifyVars: {
    ...getThemeVariables({
      dark: true, // Enable dark mode
    }),
    ...themeVariables,
  },
  webpack(config) {
    return config;
  },
};
module.exports = withPlugins([[withAntdLess, antdLessConfig]]);

Everything is working fine on running yarn dev
image
but on run yarn build then yarn start I found the style is broken
image
all the styles i added is not used

@NickBeukema
Copy link

How are you adding styles to your components? I'm having a similar issue where I'm converting an application and all of our components are imported as such, and styles are only applied in dev, not production builds:

import React, { ReactElement } from "react";
import "./Heading.less";

interface Props {}

export default function Heading(props: Props): ReactElement {
  // Removed code for brevity
  return <h1 className="heading">{props.children}</h1>
}

@SolidZORO
Copy link
Owner

@NickBeukema try #52 (comment)

@NickBeukema
Copy link

@SolidZORO I have removed all third party packages and have run yarn install --force. I'm not getting any errors in my build, and the development server runs fine, I'm just not seeing any of my custom styles included in a build.

@SolidZORO
Copy link
Owner

@SolidZORO I have removed all third party packages and have run yarn install --force. I'm not getting any errors in my build, and the development server runs fine, I'm just not seeing any of my custom styles included in a build.

can you share a demo repo for me?

@NickBeukema
Copy link

Here is a demo repo showing the issue, give the readme a read and it'll show exactly what's wrong. Thanks a ton for looking into this @SolidZORO, it's very much appreciated. Let me know if you have any other questions.

https://github.com/NickBeukema/nextjs-antd-repro

@SolidZORO
Copy link
Owner

@NickBeukema hi, you just change _app.tsx import "./global.less" to require('./global.less'); can be fixed this problem. ref. https://github.com/SolidZORO/next-plugin-antd-less#how-to-import-global-less-style-eg-stylesless

I just know it works but I don't know why.

@justjavac
Copy link

justjavac commented Feb 17, 2022

try

echo 'declare module "*.less";' > less.d.ts

or

declare module "*.less" {
  const classes: { [key: string]: string };
  export default classes;
}

@arielszabo
Copy link

Hi @SolidZORO, I'm having a similar issue with

  1. "next": "12.2.1"
  2. "next-plugin-antd-less": "1.8.0"
  3. "antd": "4.21.5"
  4. "less": "3.13.1"

When I run next dev the styles are looking fine but when building the project it seems like antd components with custom css style have the original antd style without the class I've created.

Would love your help here :)
Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants