Skip to content

Commit c219acf

Browse files
committed
refactor: 拆分CSS资源优化文件大小
1 parent d02efbe commit c219acf

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

src/main.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import "./styles/tailwind.css";
2-
import "./styles/style.scss";
3-
import "./styles/theme.scss";
4-
import "./styles/font-hack.scss";
5-
61
import Alpine from "alpinejs";
72
import upvote from "./upvote";
83
import * as tocbot from 'tocbot';

src/styles/font-pixel.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@font-face {
2+
font-family: Ark-Pixel-12-proportional-zh_cn;
3+
src: url("../fonts/fusion-pixel-12px-proportional-zh_hans.woff2");
4+
}

src/styles/main.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ html {
1010
box-sizing: inherit;
1111
}
1212

13-
@font-face {
14-
font-family: Ark-Pixel-12-proportional-zh_cn;
15-
src: url("../fonts/fusion-pixel-12px-proportional-zh_hans.woff2");
16-
}
17-
1813
body {
1914
margin: 0;
2015
padding: 0;

src/styles/style.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@tailwind base;
2+
@tailwind utilities;
3+
@tailwind components;
4+
15
@import 'buttons';
26
@import 'header';
37
@import 'logo';
@@ -6,3 +10,5 @@
610
@import 'pagination';
711
@import 'footer';
812
@import 'typed-text';
13+
14+
@import 'theme';

templates/modules/layout.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title th:text="${site.title}"></title>
8-
<link rel="stylesheet" th:href="@{/assets/dist/style.css}" href="./assets/dist/style.css" />
9-
<script th:src="@{/assets/dist/main.iife.js}"></script>
10-
<style th:if="${theme.config.basic.pixel_style}">
11-
body {
12-
font-family: Ark-Pixel-12-proportional-zh_cn, serif;
13-
}
14-
</style>
8+
<link rel="stylesheet" th:href="@{/assets/dist/style.css}" />
9+
<link rel="stylesheet" th:href="@{/assets/dist/font-hack.css}" />
10+
<th:block th:if="${theme.config.basic.pixel_style}">
11+
<link rel="stylesheet" th:href="@{/assets/dist/font-pixel.css}" />
12+
<style th:inline="css">
13+
body {
14+
font-family: Ark-Pixel-12-proportional-zh_cn, serif;
15+
}
16+
</style>
17+
</th:block>
18+
<script th:src="@{/assets/dist/main.js}"></script>
1519
</head>
1620

1721
<body class="main">

vite.config.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ import path from "path";
44
import PurgeIcons from "vite-plugin-purge-icons";
55

66
export default defineConfig({
7+
base: "",
78
plugins: [PurgeIcons()],
89
build: {
910
outDir: fileURLToPath(new URL("./templates/assets/dist", import.meta.url)),
1011
emptyOutDir: true,
11-
lib: {
12-
entry: path.resolve(__dirname, "src/main.ts"),
13-
name: "main",
14-
fileName: "main",
15-
formats: ["iife"],
12+
rollupOptions: {
13+
input: {
14+
main: path.resolve(__dirname, "src/main.ts"),
15+
style: path.resolve(__dirname, "src/styles/style.scss"),
16+
fontHack: path.resolve(__dirname, "src/styles/font-hack.scss"),
17+
fontPixel: path.resolve(__dirname, "src/styles/font-pixel.scss"),
18+
},
19+
output: {
20+
entryFileNames: "[name].js",
21+
assetFileNames: "[name].[ext]",
22+
},
1623
},
1724
},
1825
});

0 commit comments

Comments
 (0)