vite vue引入其他组件使用less 无法识别@import ~别名

上午10:50:01 [vite] Internal server error: '~ant-design-vue/es/style/themes/default.less' wasn't found. Tried - C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\@ant-design-vue\pro-layout\es\~ant-design-vue\es\style\themes\default.less,node_modules\~ant-design-vue\es\style\themes\default.less,npm://~ant-design-vue\es\style\themes\default.less,~ant-design-vue\es\style\themes\default.less
  Plugin: vite:css
  File: C:/Users/sbl_dev/Desktop/project/bcloud/node_modules/@ant-design-vue/pro-layout/es/BasicLayout.less
  1  |  @import '~ant-design-vue/es/style/themes/default.less';
     |  ^
  2  |  
  3  |  @basicLayout-prefix-cls: ~'@{ant-prefix}-pro-basicLayout';
      at less (C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:19155:33)
      at async compileCSS (C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:18837:34)
      at async TransformContext.transform (C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:18523:50)
      at async Object.transform (C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:43649:30)
      at async transformRequest (C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:59310:29)
      at async C:\Users\sbl_dev\Desktop\project\bcloud\node_modules\vite\dist\node\chunks\dep-efe32886.js:59418:32 (x2)

尝试用以下方法替换您的alias选项: 

export default defineConfig({
  // ...
  resolve: {
    alias: [
      { find: /^~/, replacement: '' }
    ],
  }
});
Logo

前往低代码交流专区

更多推荐