参考:

https://github.com/IndexXuan/vue-cli-plugin-vite

  1. vue add vite 安装插件vue-cli-plugin-vite
  2. 省略.vue的引入报错了

踩坑记录

Could not resolve “setimmediate”

hui依赖setimmediate ,安装ni setimmediate

Error: Can’t find stylesheet to import

@import ‘~hui/packages/theme/common/var-common.scss’;

https://github.com/vitejs/vite/issues/5764
sass 不支持 波浪线

  1. alias: [
  2. {
  3. find: /^~/,
  4. replacement: "",
  5. },

The requested module ‘/node_modules/.pnpm/qs@6.11.0/node_modules/qs/lib/index.js?v=e039ddcb’ does not provide an export named ‘default’

引入 @originjs/vite-plugin-CommonJS

Uncaught Error: Module “util” has been externalized for browser compatibility. Cannot access “util.custom” in client code.

https://stackoverflow.com/questions/69286329/polyfill-node-os-module-with-vite-rollup-js/70666018#70666018

  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig } from "vite";
  3. import legacy from "@vitejs/plugin-legacy";
  4. import vue2 from "@vitejs/plugin-vue2";
  5. import vue2Jsx from "@vitejs/plugin-vue2-jsx";
  6. import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
  7. import rollupNodePolyFill from "rollup-plugin-node-polyfills";
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. plugins: [
  11. vue2(),
  12. vue2Jsx(),
  13. legacy({
  14. targets: ["ie >= 11"],
  15. additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
  16. }),
  17. viteCommonjs(),
  18. ],
  19. resolve: {
  20. alias: [
  21. {
  22. find: /^~/,
  23. replacement: "",
  24. },
  25. {
  26. find: "@",
  27. replacement: fileURLToPath(new URL("./src", import.meta.url)),
  28. },
  29. {
  30. find: "util",
  31. replacement: "rollup-plugin-node-polyfills/polyfills/util",
  32. },
  33. ],
  34. },
  35. optimizeDeps: {
  36. // Vite does not work well with optionnal dependencies,
  37. // mark them as ignored for now
  38. },
  39. preprocessorOptions: {},
  40. build: {
  41. rollupOptions: {
  42. plugins: [
  43. // Enable rollup polyfills plugin, used during production bundling
  44. rollupNodePolyFill(),
  45. ],
  46. },
  47. },
  48. });

Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.

sass 版本 降为 “sass”: “~1.32.12”,

Undefined function. ╷ 10 │ $rgb: math.div

1.33.0 之后才能用

—- 没办法 还是用新版本吧