原理: Vite:由来与原理📃✅
可参考配置
https://www.yuque.com/lalala-wm82o/qvhwgq/rqcgym
https://www.yuque.com/lalala-wm82o/qvhwgq/rdyhpi
why首屏慢TODO
https://blog.csdn.net/pzy_666/article/details/123017630
https://www.cnblogs.com/hetaojs/p/15386371.html
https://github.com/willson-wang/Blog/issues/101
TODO


https://juejin.cn/post/6910014283707318279#comment

public 目录下可以存放未在源码中引用的资源,它们会被留下且文件名不会有哈希处理。

https://juejin.cn/post/6986169708722520072#heading-21

rosolve

别名

导入的别名,避免出现大量相对路径

  1. import { resolve } from "path";
  2. export default defineConfig({
  3. resolve: {
  4. alias: {
  5. // 如何配置别名 👉 https://juejin.cn/post/7006213924588617735
  6. base: resolve(__dirname, "src_crx/publicComponents/base"),
  7. basic: resolve(__dirname, "src_crx/publicComponents/basic"),
  8. },
  9. }
  10. })
  1. import { defineConfig } from "vite";
  2. import { resolve } from "path";
  3. import react from "@vitejs/plugin-react";
  4. import copy from "rollup-plugin-copy";
  5. //目录结构参考 https://juejin.cn/post/6930533407441027079#heading-1
  6. //别名规范参考 https://juejin.cn/post/6986515665926488101
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. // 别名✅&代理&数据mock
  10. // https://juejin.cn/post/6910014283707318279#heading-17
  11. resolve: {
  12. alias: {
  13. // 如何配置别名 👉 https://juejin.cn/post/7006213924588617735
  14. base: resolve(__dirname, "src_crx/publicComponents/base"),
  15. basic: resolve(__dirname, "src_crx/publicComponents/basic"),
  16. },
  17. },
  18. //
  19. plugins: [
  20. react(),
  21. copy({
  22. targets: [
  23. { src: "manifest.json", dest: "dist" },
  24. { src: "src/assets", dest: "dist" },
  25. ],
  26. hook: "writeBundle",
  27. }),
  28. ],
  29. build: {
  30. rollupOptions: {
  31. input: {
  32. // index: resolve(__dirname, "index.html"), //这个页面可以不打包出来,因为只是为了方便开发环境下的跳转
  33. popup: resolve(__dirname, "/src_crx/popup.html"),
  34. options: resolve(__dirname, "/src_crx/options.html"),
  35. "src_crx/background": "/src_crx/background.ts",
  36. "src_crx/content-script": "/src_crx/content-script.ts",
  37. "src_crx/src_content-script/main":
  38. "/src_crx/src_content-script/main.tsx", //是content-script注入的script
  39. },
  40. output: {
  41. chunkFileNames: "[name].[hash].js",
  42. assetFileNames: "[name].[hash].[ext]",
  43. entryFileNames: "[name].js",
  44. dir: "dist",
  45. },
  46. },
  47. },
  48. });

依赖预构建

https://www.vitejs.net/guide/dep-pre-bundling.html