@glimmerx/prettier-plugin-component-templates

中文文档
0.6.8发布于 2022/09/07MITCommonJS零依赖近 30 天下载 3684

A prettier formatter for glimmer component templates

原始使用文档
文档目录9 节
  1. Background
  2. Introduction
  3. Installation and Usage
  4. Options
  5. Development
  6. Debugging
  7. Generate a snapshot
  8. Testing
  9. TODO

@glimmerx/prettier-plugin-component-templates

Background

Prettier is an opinionated code formatter. In Prettier >2.0 there is support for *.hbs glimmer files, but does not support the experimental syntaxes that glimmerx components are authored in.

Introduction

This plugin extends the internal printers to add an embedded syntax for glimmer template in an hbs TaggedTemplateExpressions.

Installation and Usage

yarn add -D @glimmerx/prettier-plugin-component-templates

Once added prettier will discover and use the plugin to format any hbs tagged template expression.

Options

In your prettier config options (e.g. .prettierrc, prettier.config.js, etc.)

.prettierrc

{
  "hbsSingleQuote": true
}

Defaults to false forcing double-quotes for all attributes in an hbs embed. When true will rewrite all quotes to single-quotes.

Development

Generate a test case, add it to the tests file,

Add PRETTIER_DEBUG=true to the environment when running the plugin in order to get complete stack traces on errors.

Debugging

Debugging

PRETTIER_DEBUG=true node --inspect-brk  node_modules/.bin/prettier --config=./test/fixtures/basic/config.js ./test/fixtures/basic/code.js

Generate a snapshot

node node_modules/.bin/prettier --ignore-path --config=./test/fixtures/simple-formatted/config.js ./test/fixtures/simple-formatted/code.js > ./test/fixtures/simple-formatted/output.js

Testing

Run all tests

yarn test

TODO

  • Add support for <template> tag semantics.

版本与发布记录

@glimmerx/prettier-plugin-component-templates 共发布 4 个版本,首次发布于 2021/07/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.8latest2022/09/074 年前
0.6.72022/07/264 年前
0.6.62021/12/084 年前
0.6.52021/07/165 年前

关于 @glimmerx/prettier-plugin-component-templates 的常见问题

@glimmerx/prettier-plugin-component-templates 是什么?

A prettier formatter for glimmer component templates

如何安装 @glimmerx/prettier-plugin-component-templates?

在项目目录运行 npm install @glimmerx/prettier-plugin-component-templates,或使用 pnpm add / yarn add / bun add。

@glimmerx/prettier-plugin-component-templates 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/glimmerx__prettier-plugin-component-templates 是否存在。

@glimmerx/prettier-plugin-component-templates 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@glimmerx/prettier-plugin-component-templates 可以商用吗?

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

@glimmerx/prettier-plugin-component-templates 的下载量有多少?

根据 npm 官方下载统计,@glimmerx/prettier-plugin-component-templates 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,684 次,日均约 123 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@glimmerx/prettier-plugin-component-templates 还在维护吗?

最新版本 0.6.8 发布于 2022/09/07(4 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。