我开始使用 Vite.js,我想在项目中使用更少的文件,但我没有找到明确的解决方案来添加加载器,尤其是 less-loader,因为我使用的是 Ant Design v4。
我用了 :
import react from '@vitejs/plugin-react';
export default {
plugins: [react()],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
};
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我尝试过:
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,
},
},
},
};
Run Code Online (Sandbox Code Playgroud)
没有任何效果,我问了 chatGPT,但它给了我随机解决方案,但没有任何效果,有任何解决方案或文章来学习如何在 vite.js 中配置加载器?