两个独立问题叠在一起,用户看到的只是第一个(扫描失败会中止启动,
第二个来不及暴露)。
1) Sketch.astro 的 frontmatter 里出现字面量的 script 开标签
Astro 编译器靠扫描源码文本收集内联脚本,分不清真标签和字符串/注释。
原代码用模板字符串拼 iframe 里的 resize 脚本,那个字面量开标签被当成
组件脚本抽出来交给 Vite,里面的 ${JSON.stringify(...)} 直接报
`Expected "}" but found "{"`,dev 依赖扫描失败、整个 /src 刷红。
-> 改成 "\x3Cscript>" / "\x3C/script>" 拼接。
注意闭标签原本写作 <\/script> 所以没被误判,只有开标签要处理。
修完第一版又把解释写进注释、注释里带了字面量开标签,于是换了条错误
(`Unexpected "。"`)继续报;这次注释也改成不带字面量的写法。
2) .pnpm-store 被 Vite 的 watcher 一起监听
项目根目录下的 .pnpm-store 是 pnpm 内容寻址仓库(54269 个文件 / 672MB,
已被 .gitignore 忽略),Vite 默认 watch 项目根,直接撑爆 inotify
(max_user_watches = 65536),启动后无限刷
`ENOSPC: System limit for number of file watchers reached`。
-> astro.config.mjs 加 vite.server.watch.ignored: ["**/.pnpm-store/**"]。
顺带:package.json 加 "type": "module",消掉 Node 对
src/plugins/*.js 的 MODULE_TYPELESS_PACKAGE_JSON 警告(两个文件本来就是 ESM)。
验证
- 删掉 node_modules/.vite 强制重新做依赖扫描后启动 pnpm dev:
ERROR 0 / Failed to scan 0 / ENOSPC 0,ready in 496ms
/、/bookshelf/、/bookshelf/books/ 均 200
- pnpm build 退出码 0,MODULE_TYPELESS 警告 0
- 仅剩 [WARN] glob-loader 提示 src/content/studies 为空,属预期
- 操作指南补了这条 FAQ,说明两个原因和"注释里也不能写"这个坑
155 lines
5.2 KiB
JavaScript
155 lines
5.2 KiB
JavaScript
import { defineConfig } from "astro/config"
|
|
import react from "@astrojs/react"
|
|
import sitemap from "@astrojs/sitemap"
|
|
import mdx from "@astrojs/mdx"
|
|
import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections"
|
|
import { pluginLineNumbers } from "@expressive-code/plugin-line-numbers"
|
|
import expressiveCode from "astro-expressive-code"
|
|
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
|
import rehypeComponents from "rehype-components"
|
|
import rehypeKatex from "rehype-katex"
|
|
import rehypeSlug from "rehype-slug"
|
|
import remarkDirective from "remark-directive"
|
|
import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives"
|
|
import remarkMath from "remark-math"
|
|
import remarkSectionize from "remark-sectionize"
|
|
import { remarkShiftHeadings } from "./src/plugins/remark-shift-headings.mjs"
|
|
import { AdmonitionComponent } from "./src/plugins/rehype-component-admonition.mjs"
|
|
import { GithubCardComponent } from "./src/plugins/rehype-component-github-card.mjs"
|
|
import { parseDirectiveNode } from "./src/plugins/remark-directive-rehype.js"
|
|
import { remarkExcerpt } from "./src/plugins/remark-excerpt.js"
|
|
import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs"
|
|
import { pluginLanguageBadge } from "./src/plugins/expressive-code/language-badge"
|
|
import { pluginCustomCopyButton } from "./src/plugins/expressive-code/custom-copy-button"
|
|
import { site } from "./src/data/site"
|
|
|
|
const createAdmonitionComponent = (type) => (properties = {}, children = []) => {
|
|
const normalizedChildren = Array.isArray(children) ? children : []
|
|
return AdmonitionComponent(properties, normalizedChildren, type)
|
|
}
|
|
|
|
export default defineConfig({
|
|
srcDir: "./src",
|
|
output: "static",
|
|
site: site.url,
|
|
trailingSlash: "always",
|
|
alias: {
|
|
"@": "./src",
|
|
},
|
|
integrations: [
|
|
expressiveCode({
|
|
themes: ["github-dark", "github-light"],
|
|
themeCssSelector: (theme) => {
|
|
// 根据主题名称返回对应的 CSS 选择器
|
|
if (theme.name === "github-light") return ":root:not(.dark)"
|
|
return ".dark"
|
|
},
|
|
plugins: [
|
|
pluginCollapsibleSections(),
|
|
pluginLineNumbers(),
|
|
pluginLanguageBadge(),
|
|
pluginCustomCopyButton(),
|
|
],
|
|
defaultProps: {
|
|
wrap: true,
|
|
overridesByLang: {
|
|
shellsession: {
|
|
showLineNumbers: false,
|
|
},
|
|
},
|
|
},
|
|
styleOverrides: {
|
|
codeBackground: "var(--codeblock-bg)",
|
|
borderRadius: "0.75rem",
|
|
borderColor: "transparent",
|
|
codeFontSize: "0.875rem",
|
|
codeFontFamily: "var(--font-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
|
|
codeLineHeight: "1.625",
|
|
frames: {
|
|
editorBackground: "var(--codeblock-bg)",
|
|
terminalBackground: "var(--codeblock-bg)",
|
|
terminalTitlebarBackground: "var(--codeblock-topbar-bg)",
|
|
editorTabBarBackground: "var(--codeblock-topbar-bg)",
|
|
editorActiveTabBackground: "transparent",
|
|
editorActiveTabIndicatorBottomColor: "var(--primary)",
|
|
editorActiveTabIndicatorTopColor: "transparent",
|
|
editorTabBarBorderBottomColor: "var(--codeblock-topbar-bg)",
|
|
terminalTitlebarBorderBottomColor: "transparent",
|
|
},
|
|
},
|
|
frames: {
|
|
showCopyToClipboardButton: false,
|
|
},
|
|
}),
|
|
react(),
|
|
sitemap(),
|
|
mdx(),
|
|
],
|
|
markdown: {
|
|
remarkPlugins: [
|
|
remarkMath,
|
|
remarkReadingTime,
|
|
remarkExcerpt,
|
|
remarkShiftHeadings,
|
|
remarkGithubAdmonitionsToDirectives,
|
|
remarkDirective,
|
|
remarkSectionize,
|
|
parseDirectiveNode,
|
|
],
|
|
rehypePlugins: [
|
|
rehypeKatex,
|
|
rehypeSlug,
|
|
[
|
|
rehypeComponents,
|
|
{
|
|
components: {
|
|
github: GithubCardComponent,
|
|
note: createAdmonitionComponent("note"),
|
|
tip: createAdmonitionComponent("tip"),
|
|
important: createAdmonitionComponent("important"),
|
|
caution: createAdmonitionComponent("caution"),
|
|
warning: createAdmonitionComponent("warning"),
|
|
},
|
|
},
|
|
],
|
|
[
|
|
rehypeAutolinkHeadings,
|
|
{
|
|
behavior: "append",
|
|
properties: {
|
|
className: ["anchor"],
|
|
},
|
|
content: {
|
|
type: "element",
|
|
tagName: "span",
|
|
properties: {
|
|
className: ["anchor-icon"],
|
|
"data-pagefind-ignore": true,
|
|
},
|
|
children: [
|
|
{
|
|
type: "text",
|
|
value: "#",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
],
|
|
},
|
|
vite: {
|
|
server: {
|
|
watch: {
|
|
/*
|
|
* 项目根目录下的 .pnpm-store 是 pnpm 的内容寻址仓库:5.4 万个文件、672 MB,
|
|
* 而且已经被 .gitignore 忽略。Vite 默认会把项目根整个 watch,加上它以后
|
|
* inotify 直接到顶(max_user_watches = 65536),dev server 一启动就刷屏:
|
|
* ENOSPC: System limit for number of file watchers reached
|
|
* 排除掉即可。node_modules / .git 是 Vite 默认就排除的,不用管。
|
|
*/
|
|
ignored: ["**/.pnpm-store/**"],
|
|
},
|
|
},
|
|
},
|
|
})
|