项目架构搭建

    参考文档: https://juejin.cn/post/6938671679153373214#heading-5 https://github.com/KipSong/vite-chrome-extension

    vite.config.js的vitePluginImp中添加

    1. //👇这种方案没法自定义主题
    2. vitePluginImp({
    3. libList: [
    4. {
    5. libName: "antd",
    6. style(name) {
    7. return `antd/es/${name}/style/css.js`;
    8. },
    9. },
    10. ],
    11. }),

    上面不好自定义,于是采用下面less的方案(less方案有少量样式缺失,不知道修好没有)
    https://juejin.cn/post/6938671679153373214#heading-5
    pnpm 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;
    

    更多定制样式: https://3x.ant.design/docs/react/customize-theme-cn

    改造旧项目:
    import提示找不到module
    如果是使用绝对路径引入js,请给其父文件夹添加别名(vite.config.ts和tsconfig.json都得改)
    image.png
    image.png
    axios✅
    pnpm i axios -S

    轻服务
    https://qingfuwu.cn/dashboard/qcnxpt/function/helloworld.js?ic-function-linkarea=debug&ic-function-linkarea-debug=params&table=_dbLog

      useEffect(() => {
        axios
          .get("url")
          .then((re) => setTestApi(re.data.test));
    
        axios
          .post("url", {
            hello: "post测试啊",
          })
          .then((re) => console.log(re, "post本地"));
      }, []);
    

    常看:


    TODO:多页应用下,路由的使用存在问题
    popup.html/这里无法正常用路由,难道只能用锚点的方式?