Added wrangler compat

This commit is contained in:
Tom Butcher 2025-03-25 23:43:27 +00:00
parent 9aaa52b8d0
commit 39ff2e337e
8 changed files with 3682 additions and 562 deletions

View File

@ -1,33 +0,0 @@
{
"env": {
"browser": true,
"node": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["react", "react-hooks"],
"rules": {
"no-console": "off",
"semi": ["error", "always"],
"quotes": ["error", "double"],
"no-unused-vars": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off"
},
"settings": {
"react": {
"version": "detect"
}
}
}

31
.gitignore vendored
View File

@ -1,5 +1,28 @@
node_modules/ # Logs
build/ logs
.DS_Store
.env
*.log *.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# wrangler files
.wrangler
.dev.vars*

13
api/index.js Normal file
View File

@ -0,0 +1,13 @@
export default {
fetch(request, env) {
const url = new URL(request.url);
if (url.pathname.startsWith("/api/")) {
return Response.json({
name: "Cloudflare",
});
}
return env.ASSETS.fetch(request);
},
}

38
eslint.config.js Normal file
View File

@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]

4040
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
{ {
"name": "personal-site", "name": "personal-site",
"version": "0.1.0", "version": "0.1.0",
"type": "module",
"private": true, "private": true,
"homepage": "https://tombutcher.work", "homepage": "https://tombutcher.work",
"dependencies": { "dependencies": {
@ -24,12 +25,11 @@
"web-vitals": "^4.2.4" "web-vitals": "^4.2.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "dev": "vite",
"build": "react-scripts build", "build": "vite build",
"test": "react-scripts test", "lint": "eslint .",
"eject": "react-scripts eject", "preview": "npm run build && vite preview",
"predeploy": "npm run build", "deploy": "npm run build && wrangler deploy"
"deploy": "gh-pages -d build"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
@ -50,10 +50,17 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.57.1", "@cloudflare/vite-plugin": "^0.1.15",
"eslint-config-react-app": "^7.0.1", "@eslint/js": "^9.23.0",
"eslint-plugin-react": "^7.37.4", "@types/react": "^18.3.18",
"gh-pages": "^6.3.0", "@types/react-dom": "^18.3.5",
"globals": "^16.0.0" "@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.17.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.14.0",
"vite": "^6.0.5",
"wrangler": "^4.4.0"
} }
} }

9
vite.config.js Normal file
View File

@ -0,0 +1,9 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { cloudflare } from "@cloudflare/vite-plugin";
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), cloudflare()],
});

51
wrangler.jsonc Normal file
View File

@ -0,0 +1,51 @@
/**
* For more details on how to configure Wrangler, refer to:
* https://developers.cloudflare.com/workers/wrangler/configuration/
*/
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "tombutcher-ui",
"main": "api/index.js",
"compatibility_date": "2025-03-21",
"assets": {
"not_found_handling": "single-page-application",
"binding": "ASSETS",
},
"observability": {
"enabled": true,
},
/**
* Smart Placement
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
*/
// "placement": { "mode": "smart" },
/**
* Bindings
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
* databases, object storage, AI inference, real-time communication and more.
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
*/
/**
* Environment Variables
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
*/
// "vars": { "MY_VARIABLE": "production_value" },
/**
* Note: Use secrets to store sensitive data.
* https://developers.cloudflare.com/workers/configuration/secrets/
*/
/**
* Static Assets
* https://developers.cloudflare.com/workers/static-assets/binding/
*/
// "assets": { "directory": "./public/", "binding": "ASSETS" },
/**
* Service Bindings (communicate between multiple Workers)
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
*/
// "services": [{ "binding": "MY_SERVICE", "service": "my-service" }]
}