Alpine.js devtools
Alpine.js devtools is a simple extension to help you debug Alpine.js components easily.
This extension is heavily inspired by Vue devtools, but customized for a unique Alpine.js developer experience.
Installation
Note: if you are using Google Chrome, Alpine.js devtools will not work with local files unless you configure the extension to be allowed Access to File URLs
.
You can allow it by following these steps:
- Open chrome settings
- Go to
extensions
tab - Choose
Alpine.js devtools
and press details - Enable
Allow access to file URLs
Identifying Components
Unlike other frameworks, Alpine does not include named components. Therefore by default, Alpine.js devtools will attempt to identify component names from the following attributes, in order: id
, name
, aria-label
, x-data
(the function name), role
, and finally the tagName
.
You may also override these with either
x-title
orx-id
.
Development
Prerequisites
- Node ^14.x
- npm ^6.x
Chrome
- Clone this repo
- Run
npm install
- Run
npm run build:dev
(ornpm run build
to test a production build) - Load unpacked extension inside dist/chrome directory
- Open any HTML file that imports Alpine.js then inspect with Chrome DevTools. You should now have an Alpine.js panel available.
Firefox
- Follow the Development instructions to get a development build.
- Go to about:debugging#/runtime/this-firefox in Firefox
- Ensure you are on the "This Firefox" tab (see the left side nav)
- Click "Load Temporary Add-on..."
- Open any of the files in the built extension folder (./dist/chrome)
- Open any HTML file that imports Alpine.js then inspect with Firefox DevTools. You should now have an Alpine.js panel available.
Running the Alpine.js devtools simulator
A devtools simulator is provided in order to run tests and have an easier development workflow.
Note that when using the simulator all Chrome/Firefox devtools/Extension APIs are faked so it's useful if working on the Extension Backend (which runs in the end user's window, see packages/shell-chrome/src/backend.js
) or the Alpine.js app which runs in the devtools panel (entrypoint: packages/shell-chrome/src/devtools/app.js
).
- Clone this repo
- Run
npm install
- Run
npm start
- Open http://locahost:8080 (default port is 8080, you can override the port using the
PORT
environment variable. eg.PORT=5000 npm start
will start the simulator on http://localhost:5000) - You'll see a page with our sample Alpine.js app, example.html, running in the top half of the screen and the devtools simulator running in the bottom half of the screen.
Testing
We have 2 levels of tests in the project:
- unit tests in ./tests, written and run with uvu
- The command to run them is
npm test
.
- The command to run them is
- E2E tests that run against the devtools simulator, in ./cypress, using Cypress.
- The command to run Cypress tests is
npm run cy:run
- The command to open the Cypress UI is
npm run cy:open
- Note in order to run any Cypress tests, you'll need the simulator running (see Running the Alpine.js devtools simulator).
- The command to run Cypress tests is
Formatting/Linting
Code is auto-formatted using Prettier, see the config at .prettierrc.js.
On push, a GitHub Action will auto-format your changes.
On commit, there's a husky + lint-staged hook that runs and auto-formats your changes (unless you disable pre-commit hooks).