{"id":19201422,"url":"https://github.com/padcom/vue-ast-serializer","last_synced_at":"2025-05-12T12:42:46.653Z","repository":{"id":222617829,"uuid":"757904297","full_name":"padcom/vue-ast-serializer","owner":"padcom","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-15T08:55:22.000Z","size":98,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-03T15:02:16.975Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/padcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-15T08:21:32.000Z","updated_at":"2024-11-21T07:25:36.000Z","dependencies_parsed_at":"2024-02-15T09:48:29.161Z","dependency_job_id":null,"html_url":"https://github.com/padcom/vue-ast-serializer","commit_stats":null,"previous_names":["padcom/vue-ast-serializer"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Fvue-ast-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Fvue-ast-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Fvue-ast-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Fvue-ast-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padcom","download_url":"https://codeload.github.com/padcom/vue-ast-serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253742400,"owners_count":21957018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:38:41.392Z","updated_at":"2025-05-12T12:42:46.627Z","avatar_url":"https://github.com/padcom.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vue.js single file component (SFC) AST serializer\n\nThis library implements a serializer/stringifier for Vue.js SFC AST.\n\nThe main driver to implement something like that is to be able to add cross-cutting concerns to Vue through a Vite plugin\n\n## Usage:\n\nFirst you need to install a few dependencies:\n\n```\nnpm install @vue/compiler-sfc @vue/compiler-core @padcom/vue-ast-serializer\n```\n\nThen you can parse and serialize the content like so:\n\n```typescript\nimport { parse } from '@vue/compiler-sfc'\nimport { stringify } from '@padcom/vue-ast-serializer'\n\nconst code = '\u003ctemplate\u003e\u003c/template\u003e\u003ci18n x=\"1\"\u003e{ \"de\": { \"hello\": \"Guten Tag!\" } }\u003c/i18n\u003e'\n\nconsole.log(stringify(parse(code)))\n```\n\n## Example Vite plugin\n\nThe skeleton of a simple Vite plugin is, well.. simple:\n\n```typescript\nfunction example() {\n  return {\n    name: 'example',\n    transform(code, id) {\n      if (!id.includes('node_modules') \u0026\u0026 id.endsWith('.vue')) {\n        const parsed = parse(code)\n        const transformed = transform(parsed) // this you need to implement\n\n        return stringify(result)\n      } else {\n        return code\n      }\n    },\n  },\n}\n```\n\n## API\n\n### `function stringify(ast: SFCParseResult): string`\n\nThis function takes the result of a call to `parse` and returns a stringified version of it\n\n### `function serializeTemplate(template: SFCTemplateBlock): string`\n\nThis function takes the AST of a template block and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n\n### `function serializeScript(script: SFCScriptBlock): string`\n\nThis function takes the AST of a script block and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n\n### `function serializeStyle(style: SFCStyleBlock): string`\n\nThis function takes the AST of a style block and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n\n### `function serializeStyles(styles: SFCStyleBlock[]): string`\n\nThis function takes the AST of style blocks and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n\n### `function serializeCustomBlock(block: SFCBlock): string`\n\nThis function takes the AST of a custom block (like `\u003ci18n\u003e`) and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n\n### `function serializeCustomBlocks(blocks: SFCBlock[]): string`\n\nThis function takes the AST of custom blocks (like `\u003ci18n\u003e`) and returns a string.\nSince this block is not parsed in any way by the `parse()` function from `@vue/compuler-sfc` it is just re-created as-is.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadcom%2Fvue-ast-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadcom%2Fvue-ast-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadcom%2Fvue-ast-serializer/lists"}