项目架构搭建
参考文档: https://juejin.cn/post/6938671679153373214#heading-5 https://github.com/KipSong/vite-chrome-extension
- 基于自己的项目模板,clone后
pnpm i - antd和antd的图标
pnpm i antd @ant-design/icons -S
- 按需加载
pnpm i vite-plugin-imp -D- 用法:https://www.npmjs.com/package/vite-plugin-imp
vite.config.js的vitePluginImp中添加
//👇这种方案没法自定义主题vitePluginImp({libList: [{libName: "antd",style(name) {return `antd/es/${name}/style/css.js`;},},],}),
上面不好自定义,于是采用下面less的方案(less方案有少量样式缺失,不知道修好没有)
https://juejin.cn/post/6938671679153373214#heading-5pnpm i less-vars-to-js -D
vitePluginImp({
libList: [
{
libName: "antd",
style: (name) => `antd/lib/${name}/style/index.less`,
},
],
})
然后
...
import path from 'path'
import * as fs from "fs";
import lessToJS from "less-vars-to-js";
const themeVariables = lessToJS(
fs.readFileSync(path.resolve(__dirname, './src_global/variables.less'), 'utf8')
)
...
css: {
preprocessorOptions: {
less: {
// 支持内联 JavaScript
javascriptEnabled: true,
// 重写 less 变量,定制样式
modifyVars: themeVariables
}
}
}
...
//./src_global/variables.less
@primary-color: green;
改造旧项目:
import提示找不到module
如果是使用绝对路径引入js,请给其父文件夹添加别名(vite.config.ts和tsconfig.json都得改)

axios✅pnpm i axios -S
useEffect(() => {
axios
.get("url")
.then((re) => setTestApi(re.data.test));
axios
.post("url", {
hello: "post测试啊",
})
.then((re) => console.log(re, "post本地"));
}, []);
常看:
- axios
- typescript
- https://juejin.cn/post/6872111128135073806#heading-6
- https://juejin.cn/post/7018805943710253086#heading-73
- https://juejin.cn/post/7058868160706904078#heading-9
- https://juejin.cn/post/7002388145555636237#heading-3
- https://juejin.cn/post/7068081327857205261#heading-69
TODO:多页应用下,路由的使用存在问题
popup.html/这里无法正常用路由,难道只能用锚点的方式?
