bascik-migrate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Migrating to Bascik

迁移到 Bascik

Requires the
bascik
skill for component rules and the
bascik-scripts
skill for build-time data.
To have coding agents refactor a live site to production parity at every breakpoint and 100 in all five Lighthouse categories, install the opt-in
bascik-refactor
skill (
npx skills add bascikdev/bascik --skill bascik-refactor
) and read
node <skills-dir>/bascik/scripts/read-doc.mjs /how-to/agent-migration
.
需要
bascik
skill 提供 component 规则,并需要
bascik-scripts
skill 提供构建时数据。
如需让编码 Agent 重构线上网站,使其在每个断点都达到生产级一致性,并在 Lighthouse 的全部五个类别中取得 100 分,请安装需要主动启用的
bascik-refactor
skill(
npx skills add bascikdev/bascik --skill bascik-refactor
),并阅读
node <skills-dir>/bascik/scripts/read-doc.mjs /how-to/agent-migration
。

Procedure

步骤

  1. Inventory. List every URL, shared layout region (
    <head>
    tags, header, footer, nav), repeated widget, data source, and client behavior. Run
    node <skills-dir>/bascik/scripts/list-components.mjs
    if Bascik components already exist.
  2. Read the framework guide.
    node <skills-dir>/bascik/scripts/read-doc.mjs /switch/from-<framework>
    (
    react
    ,
    next
    ,
    vue
    ,
    svelte
    ,
    astro
    ,
    eleventy
    ,
    hugo
    ,
    wordpress
    ). Read it before writing any code; it maps each framework feature to its Bascik equivalent.
  3. Pages first. One
    .html
    per URL in
    src/pages/
    , each with its own
    <html>
    ,
    <head>
    , and
    <body>
    . Parameterized URLs become dynamic route templates.
  4. Extract components. Each page ends up as a list of tags, not a pasted block of the old site's HTML. Shared head becomes
    <site-head />
    ; header, footer, and nav become components; each section with a nameable job (hero, pricing, reviews, signup form) becomes a component; repeated widgets become one component with props and slots. Follow the old site's component boundaries where they are sound, but do not copy wrappers that only existed for the framework (providers, layout shells, one-element components) or props threaded through layers: use a slot instead. Use
    new-component.mjs
    (in the
    bascik
    skill) for the folder layout, and the
    bascik-components
    skill for where to split. Keep or improve the semantics. Carry over every semantic element the old site has (
    <nav>
    ,
    <header>
    ,
    <main>
    ,
    <article>
    ,
    <button>
    ,
    <label>
    , heading levels), and never turn semantic markup into
    <div>
    s to make a component fit. Make each component's root the element for its job (a nav component's root is the
    <nav>
    , not a
    <div>
    around it), and replace framework div soup with the right element where it is safe: a clickable
    <div>
    becomes a
    <button type="button">
    , a list of links becomes a
    <ul>
    . Checklist:
    node <skills-dir>/bascik/scripts/read-doc.mjs /component-best-practices#use-htmls-elements
    .
  5. Keep TypeScript. A TypeScript source site stays TypeScript: component logic moves to a
    .ts
    companion or an inline
    <script type="text/typescript">
    and keeps its types (prop types become the
    @bascik
    comment and the types of what the script reads), and data loaders become typed
    .ts
    helpers (beside the component or page that uses them, or in
    src/lib/
    when several share them, step 8). A JavaScript site gets TypeScript for every new file unless the person says otherwise. Erasable syntax works with no setup; for
    enum
    , decorators, or npm packages in the browser, use esbuild (the
    scripts.typescript
    snippet in the
    bascik
    skill). Docs:
    /scoped-javascript#typescript-in-component-scripts
    ,
    /configuration#scriptstypescript
    ,
    /how-to/bundling-npm-packages
    .
  6. Move styles. Delete framework scoped-style mechanisms and put the CSS in each component's companion
    .css
    . Class names stay the same; Bascik scopes them. Global styles go to
    src/pages/css/styles.css
    .
  7. Move behavior. Replace state and effects with a TypeScript script per component, targeting elements by
    id
    . Prefer HTML and CSS solutions where they exist: a framework disclosure becomes
    <details>
    , a modal becomes
    <dialog>
    , a dropdown becomes
    popover
    . Attach click handlers to
    <button>
    and
    <a>
    elements, not to
    <div>
    s, and put state a screen reader needs in ARIA attributes (
    aria-expanded
    ,
    aria-pressed
    ).
  8. Move data. Framework data loaders become
    data-bascik-build
    scripts that call typed helpers. Put each module (data, helper, types) next to its one user: in the component's folder, imported with
    ./faqs.ts
    , or beside the one page that uses it as a
    .ts
    file. Content lives with the component that renders it; a page that also needs it (JSON-LD) imports it from the component's folder. Only modules several components or pages share go in
    src/lib/
    . Do not copy the old site's
    lib/
    or
    data/
    folder as it is: per-route data parked there moves beside its user, and
    audit-components.mjs
    reports a
    src/lib/
    module with one user. Every script and helper builds its markup with
    html
    from
    @bascik/bascik/html
    (
    raw()
    for trusted or sanitized HTML,
    json()
    for JSON-LD); never port or write an escaper of your own.
  9. Verify.
    node <skills-dir>/bascik/scripts/verify.mjs --build
    and
    node <skills-dir>/bascik/scripts/audit-components.mjs
    (exit 0, or each kept warning explained), then compare old and new pages URL by URL. Do not copy confirmed responsive defects: test short portrait and landscape heights, measure text/header/section/CTA bounds, fix the owning constraint and add failing-before/passing-after tests across shared routes. Preserve unaffected layouts and record each intentional correction. Read
    read-doc.mjs /how-to/agent-migration#finding-responsive-defects
    for the investigation and parity-review procedure.
  1. 盘点。 列出所有 URL、共享布局区域(
    <head>
    标签、header、footer、nav)、重复使用的 widget、数据源和客户端行为。如果已经存在 Bascik component,请运行
    node <skills-dir>/bascik/scripts/list-components.mjs
    。
  2. 阅读框架指南。 运行
    node <skills-dir>/bascik/scripts/read-doc.mjs /switch/from-<framework>
    (
    react
    、
    next
    、
    vue
    、
    svelte
    、
    astro
    、
    eleventy
    、
    hugo
    、
    wordpress
    )。编写任何代码前先阅读该指南;它会将每个框架特性映射到对应的 Bascik 等价机制。
  3. 先处理页面。 在
    src/pages/
    中为每个 URL 创建一个
    .html
    文件,每个文件都包含自己的
    <html>
    、
    <head>
    和
    <body>
    。带参数的 URL 转换为动态路由模板。
  4. 提取 component。 最终每个页面应由一组 tag 组成,而不是直接粘贴旧站点的 HTML。共享的 head 变为
    <site-head />
    ;header、footer 和 nav 变为 component;每个承担明确任务的 section(hero、pricing、reviews、signup form)变为 component;重复使用的 widget 变为一个带 props 和 slots 的 component。旧站点中合理的 component 边界应予以沿用,但不要复制仅因框架而存在的 wrapper(providers、layout shell、单元素 component),也不要复制跨多层传递的 props:应改用 slot。使用
    new-component.mjs
    (位于
    bascik
    skill 中)创建文件夹结构,并使用
    bascik-components
    skill 确定拆分位置。 保留或改进语义。 迁移旧站点中的每个语义元素(
    <nav>
    、
    <header>
    、
    <main>
    、
    <article>
    、
    <button>
    、
    <label>
    、标题层级),绝不能为了适配 component 而将语义化 markup 改成
    <div>
    。让每个 component 的根元素成为与其职责对应的元素(nav component 的根元素应为
    <nav>
    ,而不是在外面包一个
    <div>
    ),并在安全的情况下用正确元素替换框架式 div 堆叠:可点击的
    <div>
    改为
    <button type="button">
    ,链接列表改为
    <ul>
    。检查清单:
    node <skills-dir>/bascik/scripts/read-doc.mjs /component-best-practices#use-htmls-elements
    。
  5. 保留 TypeScript。 TypeScript 源站继续保持 TypeScript:component 逻辑移至配套
    .ts
    文件,或内联
    <script type="text/typescript">
    ,并保留其类型(prop 类型变为
    @bascik
    注释以及脚本所读取内容的类型),data loader 变为带类型的
    .ts
    helper(放在使用它的 component 或页面旁;若多个位置共享,则依据步骤 8 放入
    src/lib/
    )。JavaScript 站点中的每个新文件都应使用 TypeScript,除非用户另有说明。TypeScript 的可擦除语法无需任何配置即可使用;对于浏览器中的
    enum
    、decorators 或 npm 包,使用 esbuild(
    bascik
    skill 中的
    scripts.typescript
    片段)。文档:
    /scoped-javascript#typescript-in-component-scripts
    、
    /configuration#scriptstypescript
    、
    /how-to/bundling-npm-packages
    。
  6. 迁移样式。 删除框架的作用域样式机制,将 CSS 放入每个 component 的配套
    .css
    文件。class 名称保持不变;Bascik 会自动限定其作用域。全局样式放入
    src/pages/css/styles.css
    。
  7. 迁移行为。 用每个 component 专属的 TypeScript 脚本替换 state 和 effects,并通过
    id
    定位元素。只要 HTML 和 CSS 提供了相应方案,就优先使用:框架中的 disclosure 改为
    <details>
    ,modal 改为
    <dialog>
    ,dropdown 改为
    popover
    。将 click handler 绑定到
    <button>
    和
    <a>
    ,不要绑定到
    <div>
    ;屏幕阅读器需要感知的状态放入 ARIA 属性(
    aria-expanded
    、
    aria-pressed
    )。
  8. 迁移数据。 框架 data loader 变为调用带类型 helper 的
    data-bascik-build
    脚本。将每个模块(data、helper、types)放在其唯一使用方旁边:放在 component 文件夹中并通过
    ./faqs.ts
    导入,或作为
    .ts
    文件放在使用它的页面旁。内容与渲染它的 component 放在一起;如果页面也需要该内容(例如 JSON-LD),则从 component 文件夹导入。只有被多个 component 或页面共享的模块才放入
    src/lib/
    。不要原样复制旧站点的
    lib/
    或
    data/
    目录:停放在该目录中的单路由数据应移到其使用方旁边,而
    audit-components.mjs
    会报告只有一个使用方的
    src/lib/
    模块。每个脚本和 helper 都应使用
    @bascik/bascik/html
    中的
    html
    构建 markup(可信或经过安全净化的 HTML 使用
    raw()
    ,JSON-LD 使用
    json()
    );绝不要移植或自行编写 escaper。
  9. 验证。 运行
    node <skills-dir>/bascik/scripts/verify.mjs --build
    和
    node <skills-dir>/bascik/scripts/audit-components.mjs
    (退出码为 0,或逐项说明保留 warning 的原因),然后逐个 URL 对比新旧页面。不要复制已确认存在的响应式缺陷:测试高度较小的纵向和横向视口,测量文本、header、section 和 CTA 的边界,修复引发问题的约束条件,并在共享路由上添加修复前失败、修复后通过的测试。保留未受影响的布局,并记录每项有意进行的修正。阅读
    read-doc.mjs /how-to/agent-migration#finding-responsive-defects
    ,了解调查和一致性审查流程。

Cross-framework mapping

跨框架映射

ConceptBascik
Component file (
.jsx
,
.tsx
,
.vue
,
.svelte
,
.astro
)
src/components/<name>/<name>.html
with a hyphenated name (
Card.vue
becomes
info-card
), plus
<name>.ts
for its behavior
.ts
and
.tsx
logic, prop and state types
Typed
<name>.ts
companion or
<script type="text/typescript">
; types and helpers one component uses in its folder, shared ones in
src/lib/*.ts
Scoped styles (
<style scoped>
, CSS Modules, Svelte styles)
Companion
<name>.css
, scoped automatically
children
,
<slot />
,
{@render children()}
data-bascik-slot
(no value), fallback inside
Named slots, render props, snippets
<div data-bascik-slot="x">
in the template and as the wrapper at the usage site
Props (
defineProps
,
$props()
,
props.x
)
data-bascik-prop-x
, text only
Prop bound to an attribute
data-bascik-attr-<attribute>="propName"
Object, array, or function propsNot possible: print one component per item from a build script, or embed JSON with
html`<script type="application/json">${json(data)}</script>`
useState
,
ref
,
$state
Typed variables in the component script, applied to the DOM by a function
Callback props,
$emit
,
v-model
dispatchEvent(new CustomEvent('x', { bubbles: true, detail }))
, parent listens on its root
v-if
,
{#if}
, conditional JSX
Build time: a build script prints one branch. Runtime: toggle
hidden
.map()
,
v-for
,
{#each}
Build-time loop in a build script, or clone a
<template>
at runtime
File-system routingOne
.html
per URL in
src/pages/
[slug]
,
getStaticPaths
,
generateStaticParams
, pagination
src/pages/blog/[slug].html
(or
[slug]/index.html
for trailing slashes) with
<script data-bascik-routes>
getStaticProps
,
onMounted
fetch, front matter
<script data-bascik-build>
for shared data;
fetch()
in a component script for per-visitor data
LayoutsPages keep
<html>
/
<head>
/
<body>
; layout pieces become components
Template includes with variables, filters, loops (Nunjucks, Liquid, Go templates)TypeScript helpers returning
html
values, beside their one user or in
src/lib/
when shared. Only static includes become components
Content collections (
getCollection
, Eleventy collections)
One helper (
src/lib/posts.ts
when several pages read it):
fs
read,
gray-matter
,
zod
, sort by parsed date
API routes (
app/api/x/route.ts
)
src/api/x.ts
exporting
GET
/
POST
;
context.params
is a plain object; needs
bascik --server
next/link
,
next/image
,
next/font
<a>
,
<img>
with
width
/
height
, self-hosted
@font-face
plus
<link rel="preload">
RSS/Atom feedsA
pipeline.exec
script with
phase: 'post'
writing to
BASCIK_OUT_DIR
Image optimization, syntax highlightingNot built in; add your own build step
概念Bascik
Component 文件(
.jsx
、
.tsx
、
.vue
、
.svelte
、
.astro
)
src/components/<name>/<name>.html
,名称使用连字符(
Card.vue
变为
info-card
),并使用
<name>.ts
处理行为
.ts
和
.tsx
逻辑、prop 与 state 类型
带类型的
<name>.ts
配套文件或
<script type="text/typescript">
;单个 component 使用的 types 和 helpers 放在其目录中,共享的放在
src/lib/*.ts
作用域样式(
<style scoped>
、CSS Modules、Svelte styles)
自动限定作用域的配套
<name>.css
children
、
<slot />
、
{@render children()}
data-bascik-slot
(无值),内部可提供 fallback 内容
具名 slot、render props、snippets在模板中使用
<div data-bascik-slot="x">
,并在调用位置将其作为 wrapper
Props(
defineProps
、
$props()
、
props.x
)
data-bascik-prop-x
,仅支持文本
Prop 绑定到 attribute
data-bascik-attr-<attribute>="propName"
对象、数组或函数 props不支持:在 build script 中为每个 item 输出一个 component,或嵌入 JSON:
html`<script type="application/json">${json(data)}</script>`
useState
、
ref
、
$state
component script 中带类型的变量,再由函数将其应用到 DOM
Callback props、
$emit
、
v-model
dispatchEvent(new CustomEvent('x', { bubbles: true, detail }))
,父级在 component 根元素上监听
v-if
、
{#if}
、条件 JSX
构建时:由 build script 输出一个分支。运行时:切换
hidden
.map()
、
v-for
、
{#each}
在 build script 中执行构建时循环,或在运行时克隆
<template>
文件系统路由在
src/pages/
中为每个 URL 创建一个
.html
文件
[slug]
、
getStaticPaths
、
generateStaticParams
、分页
src/pages/blog/[slug].html
(尾斜杠形式使用
[slug]/index.html
),并使用
<script data-bascik-routes>
getStaticProps
、
onMounted
fetch、front matter
共享数据使用
<script data-bascik-build>
;每位访问者的数据在 component script 中使用
fetch()
布局页面保留
<html>
/
<head>
/
<body>
;布局片段变为 component
带变量、过滤器和循环的模板 include(Nunjucks、Liquid、Go templates)TypeScript helper 返回
html
值,放在其唯一使用方旁;若被共享,则放入
src/lib/
。只有静态 include 才会变为 component
Content collections(
getCollection
、Eleventy collections)
使用一个 helper(多个页面读取时放在
src/lib/posts.ts
):通过
fs
读取,使用
gray-matter
、
zod
,并按解析后的日期排序
API routes(
app/api/x/route.ts
)
src/api/x.ts
,导出
GET
/
POST
;
context.params
是普通对象;需要
bascik --server
next/link
、
next/image
、
next/font
<a>
、带
width
/
height
的
<img>
、自托管的
@font-face
以及
<link rel="preload">
RSS/Atom feeds使用带
phase: 'post'
的
pipeline.exec
script,写入
BASCIK_OUT_DIR
图片优化、语法高亮不内置;添加自己的 build step

Gotchas that apply everywhere

适用于所有框架的注意事项

  • Build every template with
    html
    in scripts and helpers; JSX and Vue templates escaped for you, and
    html
    does the same for each value (and blocks
    javascript:
    URLs). Delete a project
    escapeHtml
    instead of porting it;
    audit-components.mjs
    reports one.
  • Component tag names need a hyphen.
  • Named-slot wrappers are removed, so wrap headings and links in a
    <div data-bascik-slot="x">
    .
  • Elements created with
    document.createElement
    get no element-selector styles.
    Clone a
    <template>
    in the component instead.
  • Production moves component scripts to the end of the document. Look up elements inside handlers or after
    DOMContentLoaded
    ; keep pre-paint scripts (theme) in
    <head>
    .
  • Re-sync form state on
    pageshow
    after Back/Forward or reload.
  • bascik --check
    reports components printed only by build scripts as unused.
    That is expected.
  • Add
    "html.validate.scripts": false
    to
    .vscode/settings.json
    (or run
    bascik init
    , which merges it in). Otherwise VS Code joins a page's
    <script>
    blocks into one file and reports false errors such as "A module cannot have multiple default exports".
  • Adapt existing editor linters; do not introduce new ones by default. Once the head moves into a component and a build script, webhint and axe report a missing charset, viewport, and
    <title>
    on source pages.
    bascik init
    leaves third-party linter configs alone. If the person uses one, preserve its settings and adapt the source exceptions in
    read-doc.mjs /testing/linting#editor-linters-read-source
    . Never add head tags back to source pages to quiet them.
  • Do not generate page files into
    src/pages/
    .
    Use dynamic routes.
  • Exclude data-reading build scripts from the cache (
    scripts.cache.exclude
    ) and watch
    content/
    (
    pipeline.watchPaths
    ).
  • Tailwind: run it as a
    pre
    exec script with
    scoping.attributes.class: false
    ; see
    read-doc.mjs /libraries
    .
  • Start from the examples for layout, SEO tags, a blog, and interactive widgets:
    add-example.mjs --list
    in the
    bascik
    skill.
  • 在脚本和 helper 中使用
    html
    构建所有模板。
    JSX 和 Vue template 会自动进行转义,
    html
    也会对每个值执行同样的转义(并阻止
    javascript:
    URL)。删除项目中的
    escapeHtml
    ,而不是移植它;
    audit-components.mjs
    会报告该函数。
  • Component tag 名称必须包含连字符。
  • 具名 slot wrapper 会被移除,因此请使用
    <div data-bascik-slot="x">
    包裹 heading 和 link。
  • 通过
    document.createElement
    创建的元素不会获得基于元素选择器的样式。
    请改为在 component 中克隆
    <template>
    。
  • 生产环境会将 component 脚本移到文档末尾。 在 handler 内部或
    DOMContentLoaded
    之后查找元素;将 pre-paint 脚本(如 theme)保留在
    <head>
    中。
  • 在 Back/Forward 操作或 reload 后,于
    pageshow
    事件中重新同步表单状态。
  • bascik --check
    会将仅由 build script 输出的 component 报告为 unused。
    这是预期行为。
  • 在
    .vscode/settings.json
    中添加
    "html.validate.scripts": false
    (或运行
    bascik init
    ,它会合并此设置)。否则 VS Code 会将一个页面中的多个
    <script>
    块合并为一个文件,并报告类似
    "A module cannot have multiple default exports"
    的误报。
  • 调整现有编辑器 linter;默认不要引入新的 linter。 当
    <head>
    被移入 component 和 build script 后,webhint 和 axe 会针对源页面报告缺少 charset、viewport 和
    <title>
    。
    bascik init
    不会改动第三方 linter 配置。如果用户使用某个 linter,请保留其设置,并按
    read-doc.mjs /testing/linting#editor-linters-read-source
    调整源文件例外。不要为了消除警告而将 head 标签重新加回源页面。
  • 不要在
    src/pages/
    中生成页面文件。
    请使用动态路由。
  • 将读取数据的 build script 排除在 cache 之外(
    scripts.cache.exclude
    ),并监视
    content/
    (
    pipeline.watchPaths
    )。
  • Tailwind: 将其作为
    pre
    exec script 运行,并设置
    scoping.attributes.class: false
    ;参见
    read-doc.mjs /libraries
    。
  • 从示例开始,了解布局、SEO 标签、博客和交互式 widget:使用
    bascik
    skill 中的
    add-example.mjs --list
    。

Existing
sitemap.xml
and
robots.txt

现有的
sitemap.xml
和
robots.txt

  1. Read both files.
  2. If they contain nothing Bascik would not generate (no hand-curated URLs, live
    Disallow
    rules, external sitemap index pointer, or bot-specific directives), delete them. Bascik generates fresh ones at build time. Do not copy them into
    src/pages/
    and do not disable
    generate.sitemap
    or
    generate.robots
    .
  3. If they contain custom directives, keep the authored file in
    src/pages/
    , set the matching
    generate
    flag to
    false
    , and add a config comment explaining why.
  4. Exclude redirect-only pages from the generated sitemap with
    <meta name="bascik-sitemap" content="exclude">
    .
Copying old files while disabling generation looks correct but freezes the sitemap at the old URL list forever.
For Astro, Eleventy, and Hugo, read the live guide with
read-doc.mjs /switch/from-astro
(or
from-eleventy
,
from-hugo
).
  1. 读取这两个文件。
  2. 如果其中不包含任何 Bascik 无法自行生成的内容(没有人工维护的 URL、当前有效的
    Disallow
    规则、外部 sitemap index 指针或针对特定 bot 的指令),则删除它们。Bascik 会在构建时生成全新的文件。不要将它们复制到
    src/pages/
    ,也不要禁用
    generate.sitemap
    或
    generate.robots
    。
  3. 如果其中包含自定义指令,则将原有文件保留在
    src/pages/
    中,将对应的
    generate
    标志设为
    false
    ,并添加一条说明原因的 config 注释。
  4. 使用
    <meta name="bascik-sitemap" content="exclude">
    将仅用于重定向的页面排除在生成的 sitemap 之外。
复制旧文件同时禁用生成功能看似正确,但会将 sitemap 永久冻结在旧 URL 列表上。
对于 Astro、Eleventy 和 Hugo,请通过
read-doc.mjs /switch/from-astro
(或
from-eleventy
、
from-hugo
)阅读当前指南。