Skip to content

Commit 2ab09f5

Browse files
committed
refactor: image use jsdelivr cdn
1 parent 8ff91ee commit 2ab09f5

36 files changed

+384
-288
lines changed

next.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ const nextConfig: NextConfig = {
1010
remotePatterns: [
1111
{
1212
protocol: 'https',
13-
hostname: 'static.jsonq.top',
13+
hostname: 'testingcf.jsdelivr.net',
1414
port: '',
1515
pathname: '/**',
1616
},
1717
{
1818
protocol: 'https',
19-
hostname: process.env.NEXT_PUBLIC_MINIO_END_POINT || '',
19+
hostname: 'jsdelivr.net',
20+
port: '',
21+
pathname: '/**',
22+
},
23+
{
24+
protocol: 'https',
25+
hostname: process.env.SITE_DOMAIN || 'jsonq.top',
2026
port: '',
2127
pathname: '/**',
2228
},

post/components/rc-template/component-build.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pnpm i clsx -D
9999

100100
代码我就不列出来了,大家可以自行编写,或者去仓库看也可以,就是一个简单的示例组件,编写完成后,目录结构如下
101101

102-
![image](https://img.jsonq.top/blog/2025/2/25/1740465671795-5ag1kxb7.png)
102+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465671795-5ag1kxb7.png)
103103

104104
- 由于样式后续要做按需导入,所以必须确保每个组件的样式 style 有一个导出的 index.(ts|js) 文件和 index.less 文件
105105
- index.(ts|js) 的内容就是 `@import xxx.less`
@@ -280,7 +280,7 @@ pnpm i rimraf -D -w
280280

281281
然后执行命令 `pnpm build`,就能在 lib 目录下看到 commonjs 的代码了,且诸多 helper 方法已被抽离至 `@babel/runtime`
282282

283-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672018-rqpzh6mq.png)
283+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672018-rqpzh6mq.png)
284284

285285
## 导出 ESM 代码
286286

@@ -349,7 +349,7 @@ const build = gulp.parallel(gulp.series(compileCJS, compileESM));
349349

350350
执行 `pnpm build`,观察 es 目录下的编译结果,都是 `import` 的 esm 写法
351351

352-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672207-ut65dlpr.png)
352+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672207-ut65dlpr.png)
353353

354354
## Less 样式处理
355355

@@ -369,7 +369,7 @@ const build = gulp.parallel(gulp.series(compileCJS, compileESM));
369369

370370
这里就举例国内采用同样技术的组件库:[antd 4.x](https://github.com/ant-design/ant-design/tree/4.x-stable)[arco design](https://github.com/arco-design/arco-design)[tdesign](https://github.com/Tencent/tdesign-react) ,可以参考一下他们的打包后的结构目录
371371

372-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672432-w93mhxcl.png)
372+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672432-w93mhxcl.png)
373373

374374
可以看到以上组件库的样式结构基本都一样(tdesign 直接使用 `cssvar`,但是对外提供了 less 能力),提供了 `index.js`(内部是 less 文件的导入)、`css.js`(内部是 css 文件的导入)`index.css`(内部是合并后的纯 css)以及原样的 less 文件
375375

@@ -403,7 +403,7 @@ const build = gulp.parallel(gulp.series(compileCJS, compileESM), copyLess);
403403

404404
可以看到 less 样式已经按照原来的结构 copy 到 es 和 lib 包中,然后就是生成 css 的步骤。
405405

406-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672606-2bccrdfz.png)
406+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672606-2bccrdfz.png)
407407

408408
### less 编译成 css
409409

@@ -435,7 +435,7 @@ const build = gulp.parallel(gulp.series(compileCJS, compileESM), copyLess, less2
435435

436436
执行 `pnpm build`,检查打包文件,如图所示就是成功的。
437437

438-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672781-6zg13c0t.png)
438+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672781-6zg13c0t.png)
439439

440440
这里没有对 css 进行压缩,esm 和 lib 会被用户以 npm 方式使用,用户打包时,自然会对 css 进行压缩。
441441

@@ -474,7 +474,7 @@ const build = gulp.parallel(gulp.series(compileCJS, compileESM), copyLess, less2
474474

475475
功能实现参考 [antd-tools](https://github.com/ant-design/antd-tools),由于 antd5 现在不使用 less 了,就直接找到之前的 commit 把代码贴出来了,如下图所示
476476

477-
![image](https://img.jsonq.top/blog/2025/2/25/1740465672947-51pmv6ad.png)
477+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465672947-51pmv6ad.png)
478478

479479
这段代码做的就是匹配到 `style/index.js` 时,生成 `style/css.js`,并通过正则将文件内容中引入的 less 文件后缀改成 css。
480480

@@ -537,7 +537,7 @@ function cssInjection(content) {
537537

538538
执行 `pnpm build`,即可看到 `css.js` 文件
539539

540-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673066-o1sbcgs5.png)
540+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673066-o1sbcgs5.png)
541541

542542
> 其实这一部分很多可以优化的地方,做的更细致一点,大家在看懂之后可以自行尝试优化,比如 `token.css` 并不存在(`token.less` 未被编译),可以去掉,再比如可以把 less 变量编译 cssvar,`css.js` 可以再额外引入 css 变量,就可以做到动态换肤功能。
543543
@@ -593,7 +593,7 @@ cssinjs 的库都不需要这个,因为 cssinjs 只有 js,天然支持 `tree
593593

594594
其实 `exports` 是用来替代 `@babel/plugin-transform-runtime``useESModules` 的(对导出这块我也不是很熟,同样是查资料和摸索出来的)
595595

596-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673182-ihgkdchv.png)
596+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673182-ihgkdchv.png)
597597

598598
而后边又添加了 `./es/*": "./es/*` 等的指向,是因为我在使用按需加载的过程中发现插件无法从 `./es` 中读取文件,找不到文件路径,而且编辑器无法给出路径提示(看样子确实是没有指定到文件下),所以才有了这一系列的指向,大家可以去掉之后自行尝试一下。
599599

@@ -645,7 +645,7 @@ storybook 分两个运行界面,一个是 vite + react 默认的模板页面
645645

646646
`App.tsx` 中导入组件
647647

648-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673340-xbx2ifpr.png)
648+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673340-xbx2ifpr.png)
649649

650650
运行 `pnpm dev`,打开即可看到一个很丑的按钮 button,因为没有样式,接下来我们做样式的按需导入
651651

@@ -688,7 +688,7 @@ export default defineConfig({
688688
689689
此时一个漂亮的按钮就成功出来了
690690
691-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673506-n68zohxm.png)
691+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673506-n68zohxm.png)
692692
693693
> 这么看来在项目结构搭建时可以把 `storybook` 作为根目录作为项目共享的配置,这样可以直接在 `components` 文件夹下写 story 文档,结构上更方便查看
694694
@@ -754,7 +754,7 @@ export const ButtonSize: Story = {
754754
755755
执行 `pnpm storybook`,运行 storybook 文档
756756
757-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673618-ctnk1wis.png)
757+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673618-ctnk1wis.png)
758758
759759
样式的按需加载也被 storybook 文档享受到了,不需要单独导入 css。
760760
@@ -891,7 +891,7 @@ module.exports = merge(prodConfig, commonConfig);
891891
892892
执行 `pnpm build:dist`,就可以看到生成了 `dist` 文件夹
893893
894-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673727-v2zl6fg7.png)
894+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673727-v2zl6fg7.png)
895895
896896
### 细节优化
897897
@@ -966,7 +966,7 @@ function less2css() {
966966
967967
执行 `pnpm build`,如图所示,就大功告成了
968968
969-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673806-8t8664tc.png)
969+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673806-8t8664tc.png)
970970
971971
> 其实 webpack 打包 dist 这块不用拆分出 `dev``prod` 两个文件,可以将配置项作为一个函数,通过传参判断构建的产物类型,作为构建脚本执行会更合适。
972972
@@ -1007,7 +1007,7 @@ function less2css() {
10071007
</html>
10081008
```
10091009
1010-
![image](https://img.jsonq.top/blog/2025/2/25/1740465673908-d60ccdoo.png)
1010+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465673908-d60ccdoo.png)
10111011
10121012
组件库的打包到此结束!同时期待阅读这篇文章的你有更深入的优化
10131013

post/components/rc-template/init-project.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pnpm i typescript less @types/node -D
6565
pnpm dlx @eslint/create-config
6666
```
6767

68-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674009-r6fksi55.png)
68+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674009-r6fksi55.png)
6969

7070
eslint 基本结构有了,再装一些辅助插件
7171

@@ -166,7 +166,7 @@ module.exports = {
166166

167167
此时你可以发现 `.prettierrc.cjs` 被 eslint 报错了
168168

169-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674140-clkgisgs.png)
169+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674140-clkgisgs.png)
170170

171171
这是由于 module 是 node 环境的全局变量,而 eslint 不识别 node 环境。在 `eslint.config.mjs` 中的 `globals` 属性添加 node 全局变量
172172

@@ -206,7 +206,7 @@ export default [
206206

207207
不出意外的话,此时就能看到 `eslint.config.mjs` 中存在大量的 prettier 报错提示。
208208

209-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674250-2ykr44hu.png)
209+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674250-2ykr44hu.png)
210210

211211
在根目录新建一个 `.vscode` 文件夹,在文件夹内部新建 `settings.json` 文件
212212

@@ -235,7 +235,7 @@ export default [
235235

236236
在 windows 上默认是 CRLF 编码,而 prettier 认为这是一种错误的编码方式,格式化也不行。
237237

238-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674347-4bgbnqhm.png)
238+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674347-4bgbnqhm.png)
239239

240240
- 安装 `EditorConfig for VS Code` 插件
241241
- 根目录新建 `.editorconfig`,写入内容,再次保存,就可以看到编码已经变成 `LF`
@@ -314,7 +314,7 @@ module.exports = {
314314

315315
完毕之后可以随便建一个测试的 less 文件,写一些内容来测试插件是否生效
316316

317-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674465-hqg9y6po.png)
317+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674465-hqg9y6po.png)
318318

319319
由此可见,排序插件是生效了,此时保存代码就可以自动修复排序规则,那这个 stylelint 的配置应该也没什么问题。
320320

@@ -604,14 +604,14 @@ const a = 1; // 'a' is assigned a value but never used.
604604

605605
然后执行 commit(初次执行代码校验时间可能较长)
606606

607-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674568-merp240h.png)
607+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674568-merp240h.png)
608608

609609
上图可以看到,lint 校验没通过,无法 commit,此时再把 `const a = 1;` 删除掉,消除 eslint 的报错,再次执行 commit
610610

611-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674709-qnpa4a7t.png)
611+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674709-qnpa4a7t.png)
612612

613613
上图可知,这次代码的校验已经通过,但是 commitlint 抛出了错误,提示 commit 信息不规范,此时修改一下再提交
614614

615-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674833-qpi6bask.png)
615+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674833-qpi6bask.png)
616616

617617
此时提交就可以正常通过了,接下来推送到远程仓库即可。

post/components/rc-template/svg-to-compoent-script.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default IconContext;
152152

153153
此时可能看到 `context.ts` 中的 React 未被使用
154154

155-
![image](https://img.jsonq.top/blog/2025/2/25/1740465674974-bmg0o4dp.png)
155+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465674974-bmg0o4dp.png)
156156

157157
这是为了兼容 react 17 及之前的旧版本,可以去 `eslint.config.mjs` 中规避一下这个问题
158158

@@ -242,7 +242,7 @@ pnpm i tsx -D
242242
243243
此时可以看到输出了 `svgs` 文件夹下的 svg 图标名称,输出结果如下:
244244
245-
![image](https://img.jsonq.top/blog/2025/2/25/1740465675083-0l7dtpth.png)
245+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465675083-0l7dtpth.png)
246246
247247
### 使用 svgr 转换组件
248248
@@ -347,7 +347,7 @@ transSvgToComponent();
347347
348348
我们生成的组件内容如下:
349349
350-
![image](https://img.jsonq.top/blog/2025/2/25/1740465675174-y867frm6.png)
350+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465675174-y867frm6.png)
351351
352352
这是 svgr 的 jsx 插件生成的,确实是一个规范的 React 组件,但不是我们想要的 React 组件:
353353
@@ -411,7 +411,7 @@ const jsxCode = await transform(
411411
412412
再次执行 `pnpm gen:icon`,查看生成的组件
413413
414-
![image](https://img.jsonq.top/blog/2025/2/25/1740465675325-ucx89ezp.png)
414+
![image](https://jsonq.top/cdn-static/2025/02/25/1740465675325-ucx89ezp.png)
415415
416416
可以看到所有的 svg 组件都使用了 Icon 组件的方法来创建,这样就相当于完成了 Icon 的创建,到这一步基本就属于大功告成了。
417417

post/css/base.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ date: 2022-10-21
2828
- 其它属性
2929
- `overflow``clip``cursor``transform``animation、transition``withe-space`
3030

31-
3. **_浏览器渲染流程_** 自上而下依次解析,解析到外部链接时 ![浏览器渲染流程](https://img.jsonq.top/blog/2025/2/25/1740465675500-gwgy42aw.jpg)
31+
3. **_浏览器渲染流程_** 自上而下依次解析,解析到外部链接时
32+
33+
![浏览器渲染流程](https://jsonq.top/cdn-static/2025/02/25/1740465675500-gwgy42aw.jpg)
3234

3335
# CSS 基本属性
3436

@@ -284,7 +286,7 @@ date: 2022-10-21
284286

285287
HTML 中的每一个元素都可以看做是一个盒子,可以具备 4 个属性
286288

287-
![盒子](https://img.jsonq.top/blog/2025/2/25/1740465675648-rmmzqf57.jpg)
289+
![盒子](https://jsonq.top/cdn-static/2025/02/25/1740465675648-rmmzqf57.jpg)
288290

289291
## 基础属性
290292

@@ -329,7 +331,7 @@ HTML 中的每一个元素都可以看做是一个盒子,可以具备 4 个属
329331

330332
### 上下 margin 的传递
331333

332-
![margin-top](https://img.jsonq.top/blog/2025/2/25/1740465675770-51b3hm0a.jpg)
334+
![margin-top](https://jsonq.top/cdn-static/2025/02/25/1740465675770-51b3hm0a.jpg)
333335

334336
- margin-top 传递
335337
- 如果**块级元素的顶部线和父元素的顶部线重叠**,那么这个**块级元素的 margin-top 值会传递给父元素**
@@ -344,7 +346,7 @@ HTML 中的每一个元素都可以看做是一个盒子,可以具备 4 个属
344346

345347
## 上下 margin 的折叠
346348

347-
![margin 的重叠问题](https://img.jsonq.top/blog/2025/2/25/1740465675867-og4w8p7b.jpg)
349+
![margin 的重叠问题](https://jsonq.top/cdn-static/2025/02/25/1740465675867-og4w8p7b.jpg)
348350

349351
- **垂直方向上相邻** 2 个 margin(margin-topmargin-bottom)有**可能会合并为 1 个 margin**,这种现象叫做 collapse(折叠)
350352
- 水平方向上的 margin(margin-leftmargin-right)永远不会 collapse
@@ -356,7 +358,7 @@ HTML 中的每一个元素都可以看做是一个盒子,可以具备 4 个属
356358
- 两个兄弟块级元素之间上下 margin 的折叠
357359
- 见上图
358360
- 父子块级元素之间 margin 的折叠
359-
- ![父子块级元素之间 margin 的折叠](https://img.jsonq.top/blog/2025/2/25/1740465675972-t618s95x.jpg)
361+
- ![父子块级元素之间 margin 的折叠](https://jsonq.top/cdn-static/2025/02/25/1740465675972-t618s95x.jpg)
360362

361363
## 常用属性
362364

post/css/scss.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ scss 写法
8181

8282
比如 `.my%placeholder{...}`,使用时 `.a{ @extend %placeholder; }` ,则会生成 `.my.a{...}`
8383

84-
![example.png](https://img.jsonq.top/blog/2025/2/25/1740465676129-loyvngd1.png)
84+
![example.png](https://jsonq.top/cdn-static/2025/02/25/1740465676129-loyvngd1.png)
8585

8686
3. 嵌套时的父选择器 `&` 使用和 less 一致
8787

@@ -208,7 +208,7 @@ $color-primary: #1677ff !default;
208208

209209
scss 在以前版本是使用 `@import` 导入 scss 文件,和 css 的 `@import` 一样,但是现在推荐使用 `@use`,因为 `@import` 会把所有变量、函数、mixin 全部引入,而 `@use` 只引入需要的变量、函数、mixin。
210210

211-
![@use 说明](https://img.jsonq.top/blog/2025/2/25/1740465676355-sezyurbd.png)
211+
![@use 说明](https://jsonq.top/cdn-static/2025/02/25/1740465676355-sezyurbd.png)
212212

213213
在使用 `@use` 的时候,如果变量、函数、mixin 重名了,会报错,所以需要使用 `as` 关键字来重命名,通常情况下,在编写样式表时才 `as *`。
214214

@@ -649,4 +649,4 @@ $base-color: #1677ff;
649649
}
650650
```
651651

652-
![色调示例](https://img.jsonq.top/blog/2025/2/25/1740465676455-mtsx3qt1.png)
652+
![色调示例](https://jsonq.top/cdn-static/2025/02/25/1740465676455-mtsx3qt1.png)

0 commit comments

Comments
 (0)