{"id":20314633,"url":"https://github.com/dashpilot/single-file-components-for-alpinejs","last_synced_at":"2025-04-11T17:17:34.485Z","repository":{"id":135256591,"uuid":"450979104","full_name":"dashpilot/single-file-components-for-alpinejs","owner":"dashpilot","description":"Svelte/Vue-inspired single-file components compiler for Alpine.js","archived":false,"fork":false,"pushed_at":"2025-02-17T12:40:04.000Z","size":54,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T13:11:30.114Z","etag":null,"topics":["alpinejs","build-tool","compiler","modular","sfc","single-file-components","tailwind","tailwindcss"],"latest_commit_sha":null,"homepage":"https://single-file-components-for-alpinejs.vercel.app","language":"HTML","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/dashpilot.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,"publiccode":null,"codemeta":null}},"created_at":"2022-01-23T01:42:20.000Z","updated_at":"2025-02-17T12:40:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"89434f33-c938-46df-b68c-6d720f5cc150","html_url":"https://github.com/dashpilot/single-file-components-for-alpinejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashpilot%2Fsingle-file-components-for-alpinejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashpilot%2Fsingle-file-components-for-alpinejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashpilot%2Fsingle-file-components-for-alpinejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashpilot%2Fsingle-file-components-for-alpinejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashpilot","download_url":"https://codeload.github.com/dashpilot/single-file-components-for-alpinejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248447600,"owners_count":21105140,"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":["alpinejs","build-tool","compiler","modular","sfc","single-file-components","tailwind","tailwindcss"],"created_at":"2024-11-14T18:16:08.129Z","updated_at":"2025-04-11T17:17:34.477Z","avatar_url":"https://github.com/dashpilot.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Single File Components for Alpine.js\n\nSvelte-inspired single-file components compiler for Alpine.js\n\n## About\n\nI love the simplicity of Alpine.js, but on bigger projects it can become a challenge to keep your code organized and modular.\n\nInspired by the way Svelte compiles your single file components into browser-friendly javascript, I created a simple compiler for Alpinejs. You write your code in single-file-component-style, and the build script compiles it to browser-friendly javascript, html and css. It also features **live-reload**, so every time you save changes to a single file component, the build script compiles your code and runs it. Although this is a basic POC, in its current form it does help you to better organize your code.\n\n## Tailwind CSS integrated\n\nBecause Alpine.js and Tailwind go so well together, I've also integrated Tailwind into the build process: every time you save a file in the `src` directory, Tailwind automatically scans your components to see which classes you've used. It then rebuilds the tailwind.css file in the `dist` folder.\n\nIf you don't want to use Tailwind, just remove the following part from package.json:\n\n`\u0026\u0026 npx tailwindcss -i ./src/tailwind.css -o ./dist/tailwind.css`\n\n## How to install?\n\n1.  run `npx degit https://github.com/dashpilot/single-file-components-for-alpinejs`\n2.  run `npm install` and then `npm run dev` to run the example components\n\n## How to create a single-file component?\n\nCreate a new .html file in `src/components`, with the following structure:\n\n    \u003ctemplate\u003e\n      \u003c!-- This is where the html of your component goes --\u003e\n      \u003cdiv class=\"example\" x-init=\"init()\" x-data=\"example()\"\u003e\n        \u003cdiv x-text=\"title\"\u003e\u003c/div\u003e\n      \u003c/div\u003e\n    \u003c/template\u003e\n\n    \u003cscript\u003e\n      // This is where your javascript goes\n      function example() {\n        return {\n          title: \"Hello world\",\n          init() {\n            console.log('Example component loaded');\n          }\n        }\n      }\n    \u003c/script\u003e\n\n    \u003cstyle\u003e\n      /* this is where your CSS goes */\n      .example{\n        border: 1px solid #DDD;\n        padding: 10px;\n      }\n    \u003c/style\u003e\n\nThe order of the template-, script- and css- tags is up to your own preference. When you run `npm run dev` or `npm run build` the compiler goes through all the components and automatically splits and minifies/uglifies the JS, CSS and HTML into dist/assets. It also copies index.html to the dist folder.\n\nTo load a component on the page, create a custom element in index.html that corresponds to the filename of your component. So if your component is called `card.html`, create a custom element `\u003ccard\u003e\u003c/card\u003e` in index.html. You can also load multiple instances of the component on the page, without duplicating the javascript or CSS.\n\nTake a look at `components/card.html` to see how well this concept actually fits Alpinejs: each component has its own data-'controller', while sharing data between components is easy via the global store (in index.html). And of course, all templating-directives are available to you (x-for, x-if, x-text, etc.)\n\n## What it's not\n\nThis script is simply meant to help you write Alpine.js code in a more modular way, but isn't a module bundler or js framework. Let me know if there are any features/improvements you'd like to see.\n\n## Press the :star: button\n\nDon't forget to press the :star: button to let me know I should continue improving this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashpilot%2Fsingle-file-components-for-alpinejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashpilot%2Fsingle-file-components-for-alpinejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashpilot%2Fsingle-file-components-for-alpinejs/lists"}