> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reform.digital/llms.txt
> Use this file to discover all available pages before exploring further.

# DevKit™ (Condensed)

> Repository template for Webflow. Includes support for private repositories, NPM publishing, and CDN deployment.

> [card] [Clone the GitHub template](https://github.com/reform-digital/webflow-devkit)

> [card] [View full version](https://docs.reform.digital/devkit.md)

![Webflow DevKit banner by Reform Digital](https://uploads-ssl.webflow.com/61700604b1b79e1cd9ef9412/6618f3d81b4b7e5a7b89c264_DevKit.png)

## Installation

**1. Setup Template**

* Click on "Use this template" in GitHub and clone as private repository.
* Open locally with GitHub Desktop and open project in Visual Studio Code.

**2. Setup NPM**

* Create NPM account
* Generate NPM Granular Access Token with read/write permissions
* Set Token Expiration: 30-90 days (recommended: 30 days)
* Copy NPM Token (not retrievable later)

**Add NPM Token to GitHub Secrets:**

**For Solo Developers:**

* Go to project repository → Settings → Secrets and variables → Actions
* New repository secret: Name `NPM_TOKEN`, paste token

**For Organization Teams:**

* **Option A (Free):** Add to each repository's secrets
* **Option B (Paid):** Add to organization secrets (requires paid plan)

**3. Setup Access Token**

* Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
* Generate new token (classic)
* Configure scopes: repo, workflow, write:packages, read:packages
* Copy token immediately (not retrievable later)

**Add PAT to GitHub Secrets:**

**For Solo Developers:**

* Go to project repository → Settings → Secrets and variables → Actions
* New repository secret: Name `PERSONAL_ACCESS_TOKEN`, paste PAT

**For Organization Teams:**

* **Option A (Free):** Add to each repository's secrets
* **Option B (Paid):** Add to organization secrets (requires paid plan)

**4. Setup VS Code**

**Install pnpm: (Skip if already installed)**

```
npm install -g pnpm
```

**Install dependencies:**

```
pnpm install
```

## How to Use DevKit™

### Building & Testing

#### Run a Local Development Server:

```
pnpm dev
```

#### Run a Local Production Server:

```
pnpm prod
```

### Pre-commit Hooks

#### Automatic Code Quality

Pre-commit hooks automatically format and lint your code before commits:

* **Prettier** formats JavaScript and CSS files in `src/`
* **ESLint** catches and auto-fixes errors
* **Commit blocked** if ESLint errors are found
* **Auto-setup** when running `pnpm install`

#### Troubleshooting

If commit is blocked:

1. Fix the linting errors shown in terminal
2. Stage fixes with `git add`
3. Commit again

### Importing Scripts

#### 1️⃣ Traditional Method:

* Operation: Run your local server using pnpm dev or pnpm prod.
* Script Logging: DevKit™ logs script tags for JavaScript and CSS files from the src folder.
* Integration: Manually copy and paste script tags to your Webflow pages or global settings, being mindful to switch between development and production tags as needed.

#### 2️⃣ Automated Method (Recommended):

#### Core DevKit™ Scripts (Global):

**`Main Settings`: Add in global `<head>` tag**

```
<!-- RD® Webflow DevKit™ / Main Settings -->
<script>
window.npmPath = "@reform-digital/sample-project@1.0.0"; // Update this once you have shipped to npm.
window.devMode = true; // Change to false in production
window.localPort = 3000; // Also change in bin/localport.js in VS Code
</script>
```

**`Style-Loader`: Add in global `<head>` tag**

```
<!-- RD® Webflow DevKit™ / Style Loader -->
<script src="https://cdn.jsdelivr.net/npm/@reform-digital/webflow-devkit-utils@1.2.1/prod/style-loader.js"></script>
```

**`Script-Loader`: Add before global `</body>` closing tag**

```
<!-- RD® Webflow DevKit™ / Script Loader -->
<script src="https://cdn.jsdelivr.net/npm/@reform-digital/webflow-devkit-utils@1.2.1/prod/script-loader.js"></script>
```

#### Project Code (Page level):

**Page `Scripts`: Add before page `</body>` closing tag**

```
<!-- RD® Webflow DevKit / Page Scripts -->
<script>
const pageScripts = ["home.js"];
loadWebflowScripts(pageScripts, npmPath);
</script>
```

**Page `Styles`: Add in page `<head>` tag**

```
<!-- RD® Webflow DevKit / Page Styles -->
<script>
const pageStyles = ["home.css"];
loadWebflowStylesheets(pageStyles, npmPath);
</script>
```

#### Project Code (Global):

**Global `Scripts`: Add before global `</body>` closing tag, under Script Loader.**

```
<!-- RD® Webflow DevKit / Global Scripts -->
<script>
const globalScripts = ["global.js", "analytics.js"];
loadWebflowScripts(globalScripts, npmPath);
</script>
```

**Global `Styles`: Add in global `<head>` tag, under Style Loader.**

```
<!-- RD® Webflow DevKit / Global Styles -->
<script>
const globalStyles = ["global.css", "animation.css"];
loadWebflowStylesheets(globalStyles, npmPath);
</script>
```

### Shipping to NPM

```
pnpm ship
```

If you are using the GitHub extension for VS Code, grant the necessary permissions if prompted.

#### Post-Shipment Steps:

**Automated:**

Update `npmPath` with your own path in the global `<head>`.

**Traditional:**

Replace local script tags located in global and page-specific `</body>` to:

```
<script src="https://cdn.jsdelivr.net/npm/@your-npm-username/your-package-name@version/your-filename.js"></script>
```

Replace local style tags in global and page-specific `<head>` to:

```
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@your-npm-username/your-package-name@version/your-filename.css">
```

### Addressing Caching

#### @latest Versioning

* Initial Release: @latest (or omitting @version) is ok for initial release.
* Subsequent Releases: @latest might lead to outdated content due to CDN and browser caching.

#### Cache Management

* CDN Cache: Manually purge via [jsDelivr’s Purge Tool](https://www.jsdelivr.com/tools/purge).
* Browser Cache: Educate users; no direct control, can only hard refresh or clear own browser cache.

#### Use Specific Versions to Prevent Caching Issues

* Automated Import: npm path `"@your-npm-username/your-package-name@version"`
* Traditional Import: src path `"https://cdn.jsdelivr.net/npm/@your-npm-username/your-package-name@version/your-filename.js"`

### Branches & Collab

#### Single Developer Workflow

* **Initial Development:** Work directly in main branch.
* **Creating a Dev Branch:** After initial release, create a dev branch.
* **Routine Development:** Work in dev, commit changes, push commits.
* **Merging and Releasing:** Merge dev into main, publish to npm.

#### Multi-Developer Collaboration Workflow

* **Setting Up Main and Dev Branches:** Ensure main and dev branches are set up.
* **Creating Feature Branches:** Developers create feature branches from dev.
* **Development, Commit, Push:** Work on feature, commit, and push.
* **Collaboration and Code Review:** Open pull requests, review code, merge into dev.
* **Syncing Changes:** Regularly fetch and merge changes from dev to avoid conflicts.
* **Adding Collaborators:** Project maintainers can add collaborators through GitHub settings.
* **Preparing for Release:** Merge dev into main, prepare for npm release.
* **Shipping to npm:** Switch to main, fetch latest, pull changes, publish to npm.

#### Conclusion

* Single developer workflow for smaller projects or initial phases.
* Multi-developer collaboration workflow for larger teams and complex projects.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.