Using vite2 + vue3 + ant-design-vue2, error message: [vite] Internal server error: Inline JavaScript is not enabled.

When developing using vite2.x + vue3 + ant-design-vue2, when the less style file of ant-design-vue is introduced, the following exception is reported:

// 引入官方提供的 less 样式入口文件
@import 'ant-design-vue/dist/antd.less';

// 全局主色
@primary-color: #354ab3; 
下午2:08:46 [vite] Internal server error: Inline JavaScript is not enabled. Is it set in your options?
  Plugin: vite:css
  File: D:/my-vite-app/node_modules/ant-design-vue/lib/style/color/bezierEasing.less
  107|  // It is hacky way to make this function will be compiled preferentially by less
  108|  // resolve error: `ReferenceError: colorPalette is not defined`
  109|  // https://github.com/ant-design/ant-motion/issues/44
     |                                                        ^
  110|  .bezierEasingMixin();
  111|  
      at less (D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:18247:33)
      at async compileCSS (D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:17943:34)
      at async TransformContext.transform (D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:17631:50)
      at async Object.transform (D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:45905:30)
      at async transformRequest (D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:61479:29)
      at async D:\my-vite-app\node_modules\vite\dist\node\chunks\dep-a5ddf8f9.js:61581:32

At this time, you need to add the following configuration in vite.config.js:

// vite2.x
css: {
  preprocessorOptions: {
    less: {
      javascriptEnabled: true,
    }
  },
},

If your project uses vite1.x, the configuration method is slightly different from vite2.x, as shown below:

// vite1.x
cssPreprocessOptions: {
  less: {
    javascriptEnabled: true,
  },
},

参考:https://vitejs.dev/config/#css-preprocessoroptions

Guess you like

Origin blog.csdn.net/baobao_123456789/article/details/113986961