Skip to content

Commit

Permalink
Merge branch 'infre-migrate-to-vite'
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-f committed Feb 7, 2024
2 parents 12d58fd + 98dffae commit 01423cc
Show file tree
Hide file tree
Showing 35 changed files with 12,496 additions and 29,527 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PORT=9001
REACT_APP_KCM_BACKEND_URL=http://localhost:3000
REACT_APP_KCM_GOOGLE_TRACKING_ID=
VITE_KCM_BACKEND_URL=http://localhost:3000
VITE_KCM_GOOGLE_TRACKING_ID=
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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: {
semi: ['warn', 'never'],
quotes: ['warn', 'single'],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
11 changes: 0 additions & 11 deletions .eslintrc.json

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
/coverage

# production
/build
/buildServer
/dist

# misc
.DS_Store
Expand Down
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine as base
FROM node:20-alpine as base

RUN apk add --no-cache su-exec tini

Expand All @@ -19,10 +19,14 @@ RUN set -ex; \
apk del .gyp;

COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node .eslintrc.json ./
COPY --chown=node:node tsconfig.node.json ./
COPY --chown=node:node nodemon-relay.json ./
COPY --chown=node:node relay.config.js ./
COPY --chown=node:node vite.config.ts ./
COPY --chown=node:node myRelayPlugin.ts ./
COPY --chown=node:node .eslintrc.cjs ./
COPY --chown=node:node relay.config.json ./
COPY --chown=node:node schema.graphql ./
COPY --chown=node:node index.html ./
COPY --chown=node:node assets ./assets
COPY --chown=node:node public ./public
COPY --chown=node:node scripts ./scripts
Expand All @@ -35,6 +39,7 @@ FROM base as development
USER node
EXPOSE 80
ENV PORT 80
ENV HOST 0.0.0.0
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["npm", "run", "dev"]

Expand Down Expand Up @@ -63,7 +68,7 @@ WORKDIR /usr/share/nginx/html
# Copy runtime data
COPY docker-entrypoint /docker-entrypoint
COPY default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build ./
COPY --from=build /app/dist ./
RUN mv ./index.html ./index.html.template

# Runtime config
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
DEST=/usr/share/nginx/html/index.html
TEMPLATE=${DEST}.template
envsubst '$REACT_APP_KCM_BACKEND_URL $REACT_APP_KCM_GOOGLE_TRACKING_ID' <${TEMPLATE} >${DEST}
envsubst '$VITE_KCM_BACKEND_URL $VITE_KCM_GOOGLE_TRACKING_ID' <${TEMPLATE} >${DEST}

exec "$@"
24 changes: 24 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="description"
content="Application for managing contacts."
/>
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" type="image/png"
href="/logo192.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>K Contact Manager</title>
</head>
<body>
<div id="root"></div>
<script>
window.kcm = {
apiUrl: "$VITE_KCM_BACKEND_URL"
};
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions myRelayPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* From https://github.com/oscartbeaumont/vite-plugin-relay */
import type { PluginOption } from 'vite'
import { transformSync } from '@babel/core'

export default {
name: 'vite:relay',
transform(src, id) {
if (/.(t|j)sx?/.test(id) && src.includes('graphql`')) {
const out = transformSync(src, {
plugins: [['babel-plugin-relay']],
code: true,
filename: id,
sourceMaps: true,
})

if (!out?.code) {
throw new Error(`vite-plugin-relay: Failed to transform ${id}`)
}

const code = out.code
const map = out.map

return {
code,
map,
}
}
},
} as PluginOption
Loading

0 comments on commit 01423cc

Please sign in to comment.