Vite默认不支持src别名
import counterReducer from "@src/pages/counter/counter.slice";
每次你都必须像这样传递完整的相对路径
import counterReducer from "../../src/pages/counter/counter.slice";
有什么办法可以缩短这些相对路径吗?
我使用 vite 创建了新的 React Typescript 应用程序
我执行npm create vite@latest然后选择typescript-swc
我不明白为什么我不能使用新的装饰器
function loggedMethod(originalMethod: any, context: ClassMethodDecoratorContext) {
console.log(context)
const methodName = String(context.name)
function replacementMethod(this: any, ...args: any[]) {
console.log(`LOG: Entering method '${methodName}'.`)
const result = originalMethod.call(this, ...args)
console.log(`LOG: Exiting method '${methodName}'.`)
return result
}
return replacementMethod
}
class Person {
name: string
constructor(name: string) {
this.name = name
}
@loggedMethod
greet() {
console.log(`Hello, my name is ${this.name}.`)
}
} …Run Code Online (Sandbox Code Playgroud) 如何在 vite.config.js 文件中添加 Vite React 项目的环境变量
我想在.env文件中添加proxy_url,并在部署时将其添加到环境中。请往下看吧!
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
const proxy_url = "http://localhost:5000/";
export default defineConfig({
plugins: [react()],
server: {
proxy: {
"/api": {
target: proxy_url,
changeOrigin: true,
rewrite: (path) => path.replace(/^/api/, ""),
},
},
},
});
Run Code Online (Sandbox Code Playgroud)
StackOverflow 上的一些博客和答案,但他们正在解决 Vue 的相同问题。这些在我的 Vite-React 项目中对我不起作用!