I started using Vite.js and I want to use less files in my project, I didn’t find a clear solution to add a loader, especially less-loader beceause I am using Ant Design v4.
I used :
import react from '@vitejs/plugin-react';
export default {
plugins: [react()],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
};
but it doesn’t work, and I tried :
import react from '@vitejs/plugin-react';
export default {
plugins: [
{
name: 'less',
transform(code, id) {
if (id.endsWith('.less')) {
return require('less').renderSync({ data: code }).css;
}
},
},
],
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
};
nothing works, I asked chatGPT but it gave me random solution and nones worked, any solution or article to learn how to configure loaders in vite.js ?
2
Answers
I am not sure what are the problems you are facing but I tried these steps and it’s working fine for me.
Installed
less
in the projectI added support for
math
,relativeUrls
along withjavascriptEnabled
in vite configHere is code sandbox link of my basic setup of
vite+reactjs+antd+less
https://codesandbox.io/p/github/abhinavRai23/Vite-react-ant-design/main
I’m having issues with a dependency that uses a second styling dependency which is using .less files.
Sorry I cannot give the names of the dependency. It’s an old internal dependency.