最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

reactjs - How to fix `[plugin:vite:css] [less] <css class> is undefined` error when apply less preprocessors? - St

matteradmin5PV0评论

I am new at using less. I initialized my codebase using npm create vite@latest. I have set the vite config as below:

  css: {
    preprocessorOptions: {
      less: {
        math: "always",
        relativeUrls: true,
        javascriptEnabled: true
      },
    },
  }

Here is my directory structure:

- src/
  - assets/
    - css/
      - commons.css
  - components/
    - Button.less
    - Button.tsx
  - App.css
  1. In App.css, I import the commons.css from assets folder @import "/src/assets/css/commons.css";
  2. In commons.css, I declare class .test { font-size: 100px }
  3. I tried to apply the .test class using mixins provided by Less. So in Button.less, I use this
// @import "/src/App.css"; // I have tried to use this import to but still doesn't work.

.btn {
  .test();
  background-color: red;
}

If I remove the mixins, the background color will applied successfully, but after I implement the mixins, it shows error [plugin:vite:css] [less] .test is undefined. My questions are:

  1. Can we import css to less?
  2. If yes, how to do it properly?

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far