@astrouxds/astro-web-components

中文文档
8.0.1发布于 2026/10/29MITTypeScriptESM + CJS近 30 天下载 4.3万

Astro Web Components

原始使用文档
文档目录3 节
  1. Quick Start
  2. Integrations
  3. Tree Shaking + Bundlers

Installation

Quick Start

To get up and running quickly, Astro web components are available via a CDN. Add the following to your <head>

<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
    href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap"
    rel="stylesheet"
/>
<link
    rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@astrouxds/astro-web-components/dist/astro-web-components/astro-web-components.css"
/>
<script
    type="module"
    src="https://cdn.jsdelivr.net/npm/@astrouxds/astro-web-components/dist/astro-web-components/astro-web-components.esm.js"
></script>

Astro components are now available anywhere in your app.

<body>
    <rux-button>Hello World</rux-button>
</body>

Integrations

  1. Install npm i @astrouxds/astro-web-components

  2. Import Astro's Fonts

<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
    href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap"
    rel="stylesheet"
/>

Roboto is used for the font. We recommend using Google's CDN; however, you can also pull down and serve your own copy of the font.

  1. Bootstrap Your Application

Static HTML (w/ ESM Modules)

// Import Astro's base styles
<link
    rel="stylesheet"
    href="/node_modules/@astrouxds/astro-web-components/dist/astro-web-components/astro-web-components.css"
/>
<script type="module">
    import { defineCustomElements } from '/node_modules/astro-web-components/loader'
    defineCustomElements()
</script>

Generic Framework

// Import Astro's base styles
import 'astro-web-components/dist/astro-web-components/astro-web-components.css'
import {
    applyPolyfills,
    defineCustomElements,
} from 'astro-web-components/loader'

applyPolyfills().then(() => {
    defineCustomElements()
})

Vue

import Vue from 'vue'
import App from './App.vue'

// Import Astro's base styles
import '@astrouxds/astro-web-components/dist/astro-web-components/astro-web-components.css'
import {
    applyPolyfills,
    defineCustomElements,
} from '@astrouxds/astro-web-components/loader'

Vue.config.productionTip = false

// Tell Vue to ignore all components defined in the astro-web-components package
Vue.config.ignoredElements = [/rux-\w*/]

// Bind the custom elements to the window object
applyPolyfills().then(() => {
    defineCustomElements()
})

new Vue({
    render: (h) => h(App),
}).$mount('#app')

Angular

  1. Include the AstroComponentsModule in any module that uses an Astro component.
import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { AstroComponentsModule } from '@astrouxds/angular'

import { AppComponent } from './app.component'

@NgModule({
    declarations: [AppComponent],
    imports: [BrowserModule, FormsModule, AstroComponentsModule],
    bootstrap: [AppComponent],
})
export class AppModule {}

Or, Define your Custom Elements in main.ts

import { enableProdMode } from '@angular/core'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'

import { AppModule } from './app/app.module'
import { environment } from './environments/environment'

// Note: loader import location set using "esmLoaderPath" within the output target config
import { defineCustomElements } from '@astrouxds/astro-web-components/loader'

if (environment.production) {
    enableProdMode()
}

platformBrowserDynamic()
    .bootstrapModule(AppModule)
    .catch((err) => console.log(err))
defineCustomElements()
  1. Setting dynamic data in for loop
<rux-classification-marking *ngFor="let type of types" [attr.classification]="type"></rux-classification-marking>

React

import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import registerServiceWorker from './registerServiceWorker'

import {
    applyPolyfills,
    defineCustomElements,
} from '@astrouxds/astro-web-components/loader'

ReactDOM.render(<App />, document.getElementById('root'))
registerServiceWorker()

applyPolyfills().then(() => {
    defineCustomElements()
})

Tree Shaking + Bundlers

Astro ships with a convenient lazy-loader, but if you'd rather more control over your build process and are using an existing bundler that supports tree shaking, you can also cherry-pick only the components you actually use. For example:

import { RuxClock } from '@astrouxds/astro-web-components/dist/components/rux-clock.js'
customElements.define('rux-clock', RuxClock)

NOTE: You will need to manually call customElements.define for every component you wish to use and their dependencies. Refer to each component's documentation to see their dependencies at a glance.

版本与发布记录

@astrouxds/astro-web-components 共发布 97 个版本,首次发布于 2021/06/24;过去 12 个月发布了 2 个版本。

版本发布日期距今
8.0.1latest2026/10/299 天前
8.0.02026/06/244 个月前
7.27.02025/09/231.1 年前
7.26.12025/07/281.3 年前
7.26.02025/06/201.4 年前
7.25.22025/05/221.5 年前

其他发布通道:6.1-rc → 0.0.0-6.1-rc-20220114175111,timeline-alpha.0 → 0.0.0-timeline-alpha.0-20220210144104,timeline-alpha.1 → 0.0.0-timeline-alpha.1-20220217190349,timeline-alpha.2 → 0.0.0-timeline-alpha.2-20220302214256,beta → 7.0.0-rc.2,latest-v6 → 6.14.0。

关于 @astrouxds/astro-web-components 的常见问题

@astrouxds/astro-web-components 是什么?

Astro Web Components

如何安装 @astrouxds/astro-web-components?

在项目目录运行 npm install @astrouxds/astro-web-components,或使用 pnpm add / yarn add / bun add。

@astrouxds/astro-web-components 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@astrouxds/astro-web-components 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@astrouxds/astro-web-components 可以商用吗?

@astrouxds/astro-web-components 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@astrouxds/astro-web-components 的下载量有多少?

根据 npm 官方下载统计,@astrouxds/astro-web-components 在 2026/10/07 – 2026/11/05 这 30 天内被下载 42,835 次,日均约 1,428 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@astrouxds/astro-web-components 还在维护吗?

最新版本 8.0.1 发布于 2026/10/29(9 天前);至今共发布 97 个版本,其中过去 12 个月发布了 2 个;首次发布于 2021/06/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。