参考:
https://github.com/IndexXuan/vue-cli-plugin-vite
- vue add vite 安装插件
vue-cli-plugin-vite
- 省略.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 不支持 波浪线
alias: [
{
find: /^~/,
replacement: "",
},
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.
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import legacy from "@vitejs/plugin-legacy";
import vue2 from "@vitejs/plugin-vue2";
import vue2Jsx from "@vitejs/plugin-vue2-jsx";
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
import rollupNodePolyFill from "rollup-plugin-node-polyfills";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue2(),
vue2Jsx(),
legacy({
targets: ["ie >= 11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
}),
viteCommonjs(),
],
resolve: {
alias: [
{
find: /^~/,
replacement: "",
},
{
find: "@",
replacement: fileURLToPath(new URL("./src", import.meta.url)),
},
{
find: "util",
replacement: "rollup-plugin-node-polyfills/polyfills/util",
},
],
},
optimizeDeps: {
// Vite does not work well with optionnal dependencies,
// mark them as ignored for now
},
preprocessorOptions: {},
build: {
rollupOptions: {
plugins: [
// Enable rollup polyfills plugin, used during production bundling
rollupNodePolyFill(),
],
},
},
});
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 之后才能用
—- 没办法 还是用新版本吧