From f171abe0f6dbf4831d7cebfe1ecd6af911dfa058 Mon Sep 17 00:00:00 2001 From: Aditya Mathur Date: Thu, 21 Mar 2024 18:42:22 +0530 Subject: [PATCH] feat: removed webpack --- .gitignore | 3 +- apps/sandbox/.swcrc | 34 ++++++++++++++ apps/sandbox/{src => api}/Card.tsx | 2 +- apps/sandbox/{src => api}/Layout.tsx | 4 +- apps/sandbox/{src => api}/Page.tsx | 6 +-- apps/sandbox/api/index.ts | 4 ++ apps/sandbox/{src => api}/main.tsx | 65 +++++++++++---------------- apps/sandbox/package.json | 6 +++ apps/sandbox/project.json | 21 ++++----- apps/sandbox/public/favicon.ico | Bin 0 -> 15406 bytes apps/sandbox/tsconfig.app.json | 12 ----- apps/sandbox/tsconfig.json | 32 +++++++++---- apps/sandbox/vercel.json | 8 ++++ apps/sandbox/webpack.config.js | 19 -------- 14 files changed, 118 insertions(+), 98 deletions(-) create mode 100644 apps/sandbox/.swcrc rename apps/sandbox/{src => api}/Card.tsx (94%) rename apps/sandbox/{src => api}/Layout.tsx (91%) rename apps/sandbox/{src => api}/Page.tsx (95%) create mode 100644 apps/sandbox/api/index.ts rename apps/sandbox/{src => api}/main.tsx (62%) create mode 100644 apps/sandbox/package.json create mode 100644 apps/sandbox/public/favicon.ico delete mode 100644 apps/sandbox/tsconfig.app.json create mode 100644 apps/sandbox/vercel.json delete mode 100644 apps/sandbox/webpack.config.js diff --git a/.gitignore b/.gitignore index 98a6e38..a2a6235 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ testem.log .DS_Store Thumbs.db -.nx/cache \ No newline at end of file +.nx/cache +.vercel diff --git a/apps/sandbox/.swcrc b/apps/sandbox/.swcrc new file mode 100644 index 0000000..6f84b7e --- /dev/null +++ b/apps/sandbox/.swcrc @@ -0,0 +1,34 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "target": "es2022", + "parser": { + "syntax": "typescript", + "decorators": true, + "dynamicImport": true + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true + }, + "keepClassNames": true, + "externalHelpers": false, + "loose": true + }, + "module": { + "type": "es6", + "strictMode": true, + "noInterop": false + }, + "minify": true, + "sourceMaps": false, + "exclude": [ + "vite.config.ts", + ".*\\.spec.tsx?$", + ".*\\.test.tsx?$", + "./src/vite-setup.ts$", + "./**/vite-setup.ts$", + ".*.js$", + "./**/__tests__/**/*" + ] +} diff --git a/apps/sandbox/src/Card.tsx b/apps/sandbox/api/Card.tsx similarity index 94% rename from apps/sandbox/src/Card.tsx rename to apps/sandbox/api/Card.tsx index 0c8c75b..661de5c 100644 --- a/apps/sandbox/src/Card.tsx +++ b/apps/sandbox/api/Card.tsx @@ -40,7 +40,7 @@ const valueClass = css` } `; -export type Card = { label: string; value: string | number }; +export type Card = { label: string; value?: string | number }; const Card: FC = ({ label, value }: Card) => { return ( diff --git a/apps/sandbox/src/Layout.tsx b/apps/sandbox/api/Layout.tsx similarity index 91% rename from apps/sandbox/src/Layout.tsx rename to apps/sandbox/api/Layout.tsx index b78b5ab..5935ead 100644 --- a/apps/sandbox/src/Layout.tsx +++ b/apps/sandbox/api/Layout.tsx @@ -1,5 +1,5 @@ import { Style, css } from "hono/css"; -import type { FC } from "hono/jsx"; +import type { FC, PropsWithChildren } from "hono/jsx"; const globalClasses = css` font-family: "Inter", sans-serif; @@ -30,7 +30,7 @@ const mainClass = css` } `; -const Layout: FC = (props) => { +const Layout: FC = (props: PropsWithChildren) => { return ( diff --git a/apps/sandbox/src/Page.tsx b/apps/sandbox/api/Page.tsx similarity index 95% rename from apps/sandbox/src/Page.tsx rename to apps/sandbox/api/Page.tsx index e086b6f..c63631a 100644 --- a/apps/sandbox/src/Page.tsx +++ b/apps/sandbox/api/Page.tsx @@ -1,8 +1,8 @@ import type { RateLimitInfo } from "hono-rate-limiter"; import { css } from "hono/css"; import type { FC } from "hono/jsx"; -import Card from "./Card"; -import Layout from "./Layout"; +import Card from "./Card.js"; +import Layout from "./Layout.js"; const checkOut = css` font-family: monospace; @@ -83,7 +83,7 @@ const Page: FC = ({ info: { limit, remaining, resetTime } }: Page) => { }, { label: "Reset", - value: resetTime.toUTCString(), + value: resetTime?.toUTCString(), }, ]; diff --git a/apps/sandbox/api/index.ts b/apps/sandbox/api/index.ts new file mode 100644 index 0000000..c862a6c --- /dev/null +++ b/apps/sandbox/api/index.ts @@ -0,0 +1,4 @@ +import { handle } from "hono/vercel"; +import { app } from "./main.js"; + +export default handle(app); diff --git a/apps/sandbox/src/main.tsx b/apps/sandbox/api/main.tsx similarity index 62% rename from apps/sandbox/src/main.tsx rename to apps/sandbox/api/main.tsx index 3252a4b..c3e95d9 100644 --- a/apps/sandbox/src/main.tsx +++ b/apps/sandbox/api/main.tsx @@ -1,38 +1,27 @@ -import { serve } from "@hono/node-server"; -import { kv } from "@vercel/kv"; -import { Hono } from "hono"; -import { type RateLimitInfo, rateLimiter } from "hono-rate-limiter"; -import { logger } from "hono/logger"; -import Page from "./Page"; - -// Init the app -const app = new Hono<{ - Variables: { - rateLimit: RateLimitInfo; - }; -}>(); - -// Adding the rate limitter -app.use( - logger(), - rateLimiter({ - windowMs: 10_000, - limit: 10, - // store: new RedisStore({ - // sendCommand: (...args: string[]) => kv.eval(...args), - // }), - handler: (_, next) => next(), - }), -); - -// Routes -app.get("/", (c) => c.html()); - -// Serving the app -const port = Number(process.env.PORT) || 3000; -console.log(`Server is running on port ${port}`); - -serve({ - fetch: app.fetch, - port, -}); +import { Hono } from "hono"; +import { type RateLimitInfo, rateLimiter } from "hono-rate-limiter"; +import { logger } from "hono/logger"; +import Page from "./Page.js"; + +// Init the app +export const app = new Hono<{ + Variables: { + rateLimit: RateLimitInfo; + }; +}>(); + +// Adding the rate limitter +app.use( + logger(), + rateLimiter({ + windowMs: 10_000, + limit: 10, + // store: new RedisStore({ + // sendCommand: (...args: string[]) => kv.eval(...args), + // }), + handler: (_, next) => next(), + }), +); + +// Routes +app.get("/", (c) => c.html()); diff --git a/apps/sandbox/package.json b/apps/sandbox/package.json new file mode 100644 index 0000000..c290fc3 --- /dev/null +++ b/apps/sandbox/package.json @@ -0,0 +1,6 @@ +{ + "type": "module", + "dependencies": { + "hono": "^4.1.3" + } +} diff --git a/apps/sandbox/project.json b/apps/sandbox/project.json index 77c8801..77aaaa0 100644 --- a/apps/sandbox/project.json +++ b/apps/sandbox/project.json @@ -1,22 +1,17 @@ { "name": "sandbox", "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/sandbox/src", + "sourceRoot": "apps/sandbox/api", "projectType": "application", "targets": { - "serve": { - "executor": "@nx/js:node", - "defaultConfiguration": "development", + "build": { + "executor": "@nx/js:swc", + "outputs": ["{options.outputPath}"], "options": { - "buildTarget": "sandbox:build" - }, - "configurations": { - "development": { - "buildTarget": "sandbox:build:development" - }, - "production": { - "buildTarget": "sandbox:build:production" - } + "outputPath": "dist/apps/sandbox", + "main": "apps/sandbox/api/index.ts", + "tsConfig": "apps/sandbox/tsconfig.json", + "assets": ["apps/sandbox/public/*"] } } }, diff --git a/apps/sandbox/public/favicon.ico b/apps/sandbox/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ace65d78173be707563d1699424a748c6c92ebb0 GIT binary patch literal 15406 zcmeHOX>e3k7H(#oA5$}9>D0{lYf64tj%BF>-5nz+raO@xK|*&HmIxvwhzwAmAczD+ z7C{t*Km<`-1{D~VLPc3!*bELt7Ks7EzL;P_Ac3rBzVE(%P4~-t-LJDa{;;cVz4z{V z&bep1=iGKUS~-5}xaAfHo~<2OH#r>lI~M8z$Iibx9Cx7) zhG2wNkB6OKtJI{pIKS7O>-V|}P^tr^kac}LZQYopmDxmo&)t9Yd0lS=`U{?B1@k#` z**A0!eq;X47Gq52LEjs5v{G}1tOp#VU*~pVB_%N~Y#zc&T!>RR%x?K)^$Mw~x-M6* zl&ey4^{T9XcWKyoj!C{jt6I;|)4V^R`>d!+g-m@!!j z4(3bhBlk;c(*06!C|`~h9F{}-_sWq2`=zd~Ru<084uwJAUsX4HkYB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0d-w>7xb>?F30B5jNPdxGuuKZZwXWtCm{iQ!j z{cVIZ@^`hIKXXdvO`8xa-zYk&cstI#dftO)VZf7v5>s59bQ=yoe#zYF;FZOu{G#98 z34PK&zmEIfgL-)z?5hnL!f$rX>)ZWa{1ZU?sXRMk5-PSIV|<)A&@LF|G}^GCWoa~}|A%+z?#dEK~13w~EY&m3aT z#ctk6huQcf&rxo)yoRd;xYV^6+?X4CT?*d@xmvCnIbURi)#_X6CFrd{euJ^bnBwd< z@rCV2Y#%m=IhJU8#tPO5^{r?(lj3gQ%aC!TEM-mz~X#;u|6OaGBRSZGcqCZHP8 znZBPMf9E-ZvIhQQEOi^oQSfjuwiI|j%DXjqpUX2J&rLjgsQWYUfg1tBuS0&NK$9u( EKN~wWT>t<8 literal 0 HcmV?d00001 diff --git a/apps/sandbox/tsconfig.app.json b/apps/sandbox/tsconfig.app.json deleted file mode 100644 index 34442df..0000000 --- a/apps/sandbox/tsconfig.app.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["node", "express"], - "jsx": "react-jsx", - "jsxImportSource": "hono/jsx" - }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], - "include": ["src/**/*.ts", "src/**/*.tsx"] -} diff --git a/apps/sandbox/tsconfig.json b/apps/sandbox/tsconfig.json index 4f01f4e..87417ab 100644 --- a/apps/sandbox/tsconfig.json +++ b/apps/sandbox/tsconfig.json @@ -1,13 +1,27 @@ { "extends": "../../tsconfig.base.json", - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.app.json" - } - ], "compilerOptions": { - "esModuleInterop": true - } + "module": "esnext", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "target": "ESNext", + "moduleResolution": "node", + "esModuleInterop": true, + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx", + "outDir": "../../dist/out-tsc", + "declaration": true + }, + + "include": ["api/**/*.ts", "api/**/*.tsx"], + "exclude": [ + "vite.config.ts", + "api/**/*.spec.ts", + "api/**/*.test.ts", + "./**/__tests__/*" + ] } diff --git a/apps/sandbox/vercel.json b/apps/sandbox/vercel.json new file mode 100644 index 0000000..e444901 --- /dev/null +++ b/apps/sandbox/vercel.json @@ -0,0 +1,8 @@ +{ + "rewrites": [ + { + "source": "/(.*)", + "destination": "/api" + } + ] +} diff --git a/apps/sandbox/webpack.config.js b/apps/sandbox/webpack.config.js deleted file mode 100644 index b00ade3..0000000 --- a/apps/sandbox/webpack.config.js +++ /dev/null @@ -1,19 +0,0 @@ -const { NxWebpackPlugin } = require("@nx/webpack"); -const { join } = require("node:path"); - -module.exports = { - output: { - path: join(__dirname, "../../dist/apps/sandbox"), - }, - plugins: [ - new NxWebpackPlugin({ - target: "node", - compiler: "tsc", - main: "./src/main.tsx", - tsConfig: "./tsconfig.app.json", - // assets: ["./src/assets"], - optimization: false, - outputHashing: "none", - }), - ], -};