From 2f23313afdd68ba775f09194a2bf4b20e2df8ebe Mon Sep 17 00:00:00 2001 From: salvatorelaspata Date: Wed, 31 Jan 2024 23:01:52 +0100 Subject: [PATCH 1/2] simple demo with small link component --- vite-tailwind/.eslintrc.cjs | 18 ++ vite-tailwind/.gitignore | 24 ++ vite-tailwind/README.md | 30 +++ vite-tailwind/index.html | 21 ++ vite-tailwind/package.json | 31 +++ vite-tailwind/postcss.config.js | 6 + vite-tailwind/public/vite.svg | 1 + vite-tailwind/socket.ini | 311 ++++++++++++++++++++++++++ vite-tailwind/src/App.tsx | 37 +++ vite-tailwind/src/assets/react.svg | 1 + vite-tailwind/src/components/Link.tsx | 21 ++ vite-tailwind/src/index.css | 3 + vite-tailwind/src/main.tsx | 10 + vite-tailwind/src/vite-env.d.ts | 1 + vite-tailwind/tailwind.config.js | 12 + vite-tailwind/tsconfig.json | 25 +++ vite-tailwind/tsconfig.node.json | 10 + vite-tailwind/vite.config.ts | 7 + 18 files changed, 569 insertions(+) create mode 100644 vite-tailwind/.eslintrc.cjs create mode 100644 vite-tailwind/.gitignore create mode 100644 vite-tailwind/README.md create mode 100644 vite-tailwind/index.html create mode 100644 vite-tailwind/package.json create mode 100644 vite-tailwind/postcss.config.js create mode 100644 vite-tailwind/public/vite.svg create mode 100644 vite-tailwind/socket.ini create mode 100644 vite-tailwind/src/App.tsx create mode 100644 vite-tailwind/src/assets/react.svg create mode 100644 vite-tailwind/src/components/Link.tsx create mode 100644 vite-tailwind/src/index.css create mode 100644 vite-tailwind/src/main.tsx create mode 100644 vite-tailwind/src/vite-env.d.ts create mode 100644 vite-tailwind/tailwind.config.js create mode 100644 vite-tailwind/tsconfig.json create mode 100644 vite-tailwind/tsconfig.node.json create mode 100644 vite-tailwind/vite.config.ts diff --git a/vite-tailwind/.eslintrc.cjs b/vite-tailwind/.eslintrc.cjs new file mode 100644 index 0000000..d6c9537 --- /dev/null +++ b/vite-tailwind/.eslintrc.cjs @@ -0,0 +1,18 @@ +module.exports = { + root: true, + env: { browser: true, es2020: true }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:react-hooks/recommended', + ], + ignorePatterns: ['dist', '.eslintrc.cjs'], + parser: '@typescript-eslint/parser', + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, +} diff --git a/vite-tailwind/.gitignore b/vite-tailwind/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/vite-tailwind/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.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? diff --git a/vite-tailwind/README.md b/vite-tailwind/README.md new file mode 100644 index 0000000..0d6babe --- /dev/null +++ b/vite-tailwind/README.md @@ -0,0 +1,30 @@ +# React + TypeScript + Vite + +This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. + +Currently, two official plugins are available: + +- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh +- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh + +## Expanding the ESLint configuration + +If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: + +- Configure the top-level `parserOptions` property like this: + +```js +export default { + // other rules... + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: ['./tsconfig.json', './tsconfig.node.json'], + tsconfigRootDir: __dirname, + }, +} +``` + +- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` +- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/vite-tailwind/index.html b/vite-tailwind/index.html new file mode 100644 index 0000000..2387ae3 --- /dev/null +++ b/vite-tailwind/index.html @@ -0,0 +1,21 @@ + + + + + + + + Socket Supply - Vite - React - TailwindCSS + + +
+ + + diff --git a/vite-tailwind/package.json b/vite-tailwind/package.json new file mode 100644 index 0000000..5496e57 --- /dev/null +++ b/vite-tailwind/package.json @@ -0,0 +1,31 @@ +{ + "name": "vite-tailwind", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview" + }, + "dependencies": { + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@types/react": "^18.2.43", + "@types/react-dom": "^18.2.17", + "@typescript-eslint/eslint-plugin": "^6.14.0", + "@typescript-eslint/parser": "^6.14.0", + "@vitejs/plugin-react": "^4.2.1", + "autoprefixer": "^10.4.17", + "eslint": "^8.55.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.5", + "postcss": "^8.4.33", + "tailwindcss": "^3.4.1", + "typescript": "^5.2.2", + "vite": "^5.0.8" + } +} diff --git a/vite-tailwind/postcss.config.js b/vite-tailwind/postcss.config.js new file mode 100644 index 0000000..2e7af2b --- /dev/null +++ b/vite-tailwind/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/vite-tailwind/public/vite.svg b/vite-tailwind/public/vite.svg new file mode 100644 index 0000000..e7b8dfb --- /dev/null +++ b/vite-tailwind/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vite-tailwind/socket.ini b/vite-tailwind/socket.ini new file mode 100644 index 0000000..7829c78 --- /dev/null +++ b/vite-tailwind/socket.ini @@ -0,0 +1,311 @@ + +; ___ __ ___ __ ____ +; /__ / / / /_/ /_ / +; __/ /__/ /__ / \ /__ / +; +; Socket ⚡︎ Runtime · A modern runtime for Web Apps · v0.5.4 (f90ba121) +; + +; The value of the "script" property in the build section will be interpreted as +; a shell command when you run "ssc build". This is the most important command +; in this file. It will do all the heavy lifting and should handle 99.9% of your +; use cases for moving files into place or tweaking platform-specific build +; artifacts. If you don't specify it, ssc will just copy everything in your +; project to the build target. +; +; Note that "~" alias won't expand to the home directory in any of the config +; files. Use the full path instead. + +[build] + +; ssc will copy everything in this directory to the build output directory. +; This is useful when you want to avoid bundling or want to use tools like +; vite, webpack, rollup, etc. to build your project and then copy output to +; the Socket bundle resources directory. +; default value: "src" +copy = "dist" + +; An ini file that maps files from the source directory to the build directory. +; copy_map = src/mapping.ini + +; An list of environment variables, separated by commas. +env = USER, TMPDIR, PWD + +; Advanced Compiler Settings (ie C++ compiler -02, -03, etc). +flags = -O3 + +; If true, the window will never be displayed. +; default value: false +headless = false + +; The name of the program and executable to be output. Can't contain spaces or special characters. Required field. +name = "vite-tailwind" + +; The binary output path. It's recommended to add this path to .gitignore. +; default value: "build" +output = "build" + +; The build script +script = "npm run build" + +; The build script. It runs before the `[build] copy` phase. +; script = "npm run build" + +[build.script] +; If true, it will pass build arguments to the build script. WARNING: this could be deprecated in the future. +; default value: false +forward_arguments = false + +[build.watch] +; Configure your project to watch for sources that could change when running `ssc`. +; Could be a string or an array of strings +sources[] = "src" + + +[webview] +; Make root open index.html +; default value: "/" +root = "/" + +; Set default 'index.html' path to open for implicit routes +; default value: "" +; default_index = "" + +; Tell the webview to watch for changes in its resources +; default value: false +watch = true + +[webview.watch] +; Configure webview to reload when a file changes +; default value: true +reload = true + +; Mount file system paths in webview navigator +[webview.navigator.mounts] +; $HOST_HOME/directory-in-home-folder/ = /mount/path/in/navigator +; $HOST_CONTAINER/directory-app-container/ = /mount/path/in/navigator +; $HOST_PROCESS_WORKING_DIRECTORY/directory-in-app-process-working-directory/ = /mount/path/in/navigator + +[permissions] +; Allow/Disallow fullscreen in application +; default value: true +; allow_fullscreen = true + +; Allow/Disallow microphone in application +; default value: true +; allow_microphone = true + +; Allow/Disallow camera in application +; default value: true +; allow_camera = true + +; Allow/Disallow user media (microphone + camera) in application +; default value: true +; allow_user_media = true + +; Allow/Disallow geolocation in application +; default value: true +; allow_geolocation = true + +; Allow/Disallow notifications in application +; default value: true +; allow_notifications = true + +; Allow/Disallow sensors in application +; default value: true +; allow_sensors = true + +; Allow/Disallow clipboard in application +; default value: true +; allow_clipboard = true + +; Allow/Disallow bluetooth in application +; default value: true +; allow_bluetooth = true + +; Allow/Disallow data access in application +; default value: true +; allow_data_access = true + +; Allow/Disallow AirPlay access in application (macOS/iOS) only +; default value: true +; allow_airplay = true + + +[debug] +; Advanced Compiler Settings for debug purposes (ie C++ compiler -g, etc). +flags = "-g" + + +[meta] + +; A unique ID that identifies the bundle (used by all app stores). +; It's required when `[meta] type` is not `"extension"`. +; It should be in a reverse DNS notation https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion +bundle_identifier = "com.vite-tailwind" + +; A unique application protocol scheme to support deep linking +; If this value is not defined, then it is derived from the `[meta] bundle_identifier` value +application_protocol = "vite-tailwind" + +; A string that gets used in the about dialog and package meta info. +; copyright = "(c) Beep Boop Corp. 1985" + +; A short description of the app. +; description = "A UI for the beep boop network" + +; Set the limit of files that can be opened by your process. +file_limit = 1024 + +; Localization +lang = "en-us" + +; A String used in the about dialog and meta info. +; maintainer = "Beep Boop Corp." + +; The title of the app used in metadata files. This is NOT a window title. Can contain spaces and special characters. Defaults to name in a [build] section. +title = "vite-tailwind" + +; Builds an extension when set to "extension". +; default value: "" +; type = "" + +; A string that indicates the version of the application. It should be a semver triple like 1.2.3. Defaults to 1.0.0. +version = 1.0.0 + + +[android] +; The icon to use for identifying your app on Android. +icon = "src/icon.png" + +; Extensions of files that will not be stored compressed in the APK. +aapt_no_compress = "" + +; Enables gradle based ndk build rather than using external native build (standard ndk is the old slow way) +enable_standard_ndk_build = false + +; Name of the MainActivity class. Could be overwritten by custom native code. +main_activity = "" + +; Which permissions does your application need: https://developer.android.com/guide/topics/permissions/overview +manifest_permissions = "" + +; To restrict the set of ABIs that your application supports, set them here. +native_abis = "" + +; Used for adding custom source files and related compiler attributes. +native_cflags = "" +native_sources = "" +native_makefile = "" +sources = "" + + +[ios] + +; signing guide: https://socketsupply.co/guides/#ios-1 +codesign_identity = "" + +; Describes how Xcode should export the archive. Available options: app-store, package, ad-hoc, enterprise, development, and developer-id. +distribution_method = "ad-hoc" + +; A path to the provisioning profile used for signing iOS app. +provisioning_profile = "" + +; which device to target when building for the simulator. +simulator_device = "iPhone 14" + +; Indicate to Apple if you are using encryption that is not exempt. +; default value: false +; nonexempt_encryption = false + +[linux] +; Helps to make your app searchable in Linux desktop environments. +categories = "Developer Tools" + +; The command to execute to spawn the "back-end" process. +; cmd = "node backend/index.js" + +; The icon to use for identifying your app in Linux desktop environments. +icon = "src/icon.png" + + +[mac] + +; A category in the App Store +category = "" + +; The command to execute to spawn the "back-end" process. +; cmd = "node backend/index.js" + +; The icon to use for identifying your app on MacOS. +icon = "src/icon.png" + +; TODO Signing guide: https://socketsupply.co/guides/#code-signing-certificates +codesign_identity = "" + +; Additional paths to codesign +codesign_paths = "" + + +[native] + +; Files that should be added to the compile step. +files = native-module1.cc native-module2.cc + +; Extra Headers +headers = native-module1.hh + + +[win] + +; The command to execute to spawn the “back-end” process. +; cmd = "node backend/index.js" + +; The icon to use for identifying your app on Windows. +icon = "src/icon.png" + +; The icon to use for identifying your app on Windows. +logo = "src/icons/icon.png" + +; A relative path to the pfx file used for signing. +; pfx = "certs/cert.pfx" + +; The signing information needed by the appx api. +; publisher = "CN=Beep Boop Corp., O=Beep Boop Corp., L=San Francisco, S=California, C=US" + + +[window] + +; The initial height of the first window. +height = 50% + +; The initial width of the first window. +width = 50% + +[headless] + +; The headless runner command. It is used when no OS specific runner is set. +runner = "" +; The headless runner command flags. It is used when no OS specific runner is set. +runner_flags = "" +; The headless runner command for Android +runner_android = "" +; The headless runner command flags for Android +runner_android_flags = "" +; The headless runner command for iOS +runner_ios = "" +; The headless runner command flags for iOS +runner_ios_flags = "" +; The headless runner command for Linux +runner_linux = "" +; The headless runner command flags for Linux +runner_linux_flags = "" +; The headless runner command for MacOS +runner_mac = "" +; The headless runner command flags for MacOS +runner_mac_flags = "" +; The headless runner command for Windows +runner_win32 = "" +; The headless runner command flags for Windows +runner_win32_flags = "" + diff --git a/vite-tailwind/src/App.tsx b/vite-tailwind/src/App.tsx new file mode 100644 index 0000000..d95c6fa --- /dev/null +++ b/vite-tailwind/src/App.tsx @@ -0,0 +1,37 @@ +import { useState } from 'react' +import Link from './components/Link' + +function App () { + const [count, setCount] = useState(0) + + return ( + <> +
+

👋 Socket Supply + Vite + React!

+ + + + +

+ Edit App.tsx and save to test HMR updates. +

+ +
+ + {' | '} + + {' | '} + +
+
+ + ) +} + +export default App diff --git a/vite-tailwind/src/assets/react.svg b/vite-tailwind/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/vite-tailwind/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vite-tailwind/src/components/Link.tsx b/vite-tailwind/src/components/Link.tsx new file mode 100644 index 0000000..a830c73 --- /dev/null +++ b/vite-tailwind/src/components/Link.tsx @@ -0,0 +1,21 @@ +interface LinkProps { + href: string + text: string, + tabIndex: number +} +const Link: React.FC = ({ href, text, tabIndex }) => { + return ( + + + {text} + + ) +} + +export default Link \ No newline at end of file diff --git a/vite-tailwind/src/index.css b/vite-tailwind/src/index.css new file mode 100644 index 0000000..274aa0a --- /dev/null +++ b/vite-tailwind/src/index.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities \ No newline at end of file diff --git a/vite-tailwind/src/main.tsx b/vite-tailwind/src/main.tsx new file mode 100644 index 0000000..3d7150d --- /dev/null +++ b/vite-tailwind/src/main.tsx @@ -0,0 +1,10 @@ +import React from 'react' +import ReactDOM from 'react-dom/client' +import App from './App.tsx' +import './index.css' + +ReactDOM.createRoot(document.getElementById('root')!).render( + + + , +) diff --git a/vite-tailwind/src/vite-env.d.ts b/vite-tailwind/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/vite-tailwind/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/vite-tailwind/tailwind.config.js b/vite-tailwind/tailwind.config.js new file mode 100644 index 0000000..d37737f --- /dev/null +++ b/vite-tailwind/tailwind.config.js @@ -0,0 +1,12 @@ +/** @type {import('tailwindcss').Config} */ +export default { + content: [ + "./index.html", + "./src/**/*.{js,ts,jsx,tsx}", + ], + theme: { + extend: {}, + }, + plugins: [], +} + diff --git a/vite-tailwind/tsconfig.json b/vite-tailwind/tsconfig.json new file mode 100644 index 0000000..a7fc6fb --- /dev/null +++ b/vite-tailwind/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/vite-tailwind/tsconfig.node.json b/vite-tailwind/tsconfig.node.json new file mode 100644 index 0000000..42872c5 --- /dev/null +++ b/vite-tailwind/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/vite-tailwind/vite.config.ts b/vite-tailwind/vite.config.ts new file mode 100644 index 0000000..5a33944 --- /dev/null +++ b/vite-tailwind/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], +}) From 2b8e347c88dcf87b996e39c5ccf08fe0a77d5ff9 Mon Sep 17 00:00:00 2001 From: salvatorelaspata Date: Wed, 31 Jan 2024 23:20:05 +0100 Subject: [PATCH 2/2] improve readme instruction --- vite-tailwind/README.md | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/vite-tailwind/README.md b/vite-tailwind/README.md index 0d6babe..5a87457 100644 --- a/vite-tailwind/README.md +++ b/vite-tailwind/README.md @@ -1,30 +1,28 @@ -# React + TypeScript + Vite +# vite-tailwind -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. +This template should help get you started developing with [SocketSupply](https://socketsupply.co) and [React](https://reactjs.org). -Currently, two official plugins are available: +The template uses [Vite](https://vitejs.dev/) as the bundler and [TailwindCSS](https://tailwindcss.com/) for styling. -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh +# Prerequisites -## Expanding the ESLint configuration +- Socket runtime CLI [docs](https://socketsupply.co/guides/#quick-start) +- NodeJS [docs](https://nodejs.org/en/) -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: +## Project setup -- Configure the top-level `parserOptions` property like this: +``` +npm install +``` -```js -export default { - // other rules... - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.node.json'], - tsconfigRootDir: __dirname, - }, -} +## SSC development + +``` +ssc build -r ``` -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list +## local development + +``` +npm run dev +```