Skip to content

Commit

Permalink
Merge pull request #6 from azizghuloum/using-vite
Browse files Browse the repository at this point in the history
migrating to vite
  • Loading branch information
azizghuloum authored Sep 27, 2024
2 parents a2f4a72 + 132d22f commit e87b68a
Show file tree
Hide file tree
Showing 30 changed files with 2,378 additions and 20,964 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
- run: (cd context-free && docker build . -t contextfree -f Wasm.Dockerfile)
- name: Build the Docker image
run: docker build . --file Dockerfile --tag context-free-web
- run: (container=$(docker create context-free-web) && docker cp ${container}:/app/build ./build)
- run: (container=$(docker create context-free-web) && docker cp ${container}:/app/dist ./dist)
- uses: actions/upload-pages-artifact@v3
with:
name: github-pages
path: ./build
path: ./dist
retention-days: 90
deploy:
if: github.ref == 'refs/heads/main'
Expand Down
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN apt install curl vim -y
RUN curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt install -y nodejs
RUN npm install -g serve


RUN mkdir /app
Expand All @@ -21,16 +20,20 @@ RUN npm install
RUN mkdir /cfdg
# COPY --from=cfdg /context-free/web/cfdg.wasm /cfdg
# COPY --from=cfdg /context-free/web/cfdg.wasm.map /cfdg
COPY --from=cfdg /context-free/web/cfdg.js /cfdg
RUN echo "module.exports = Module;" >> /cfdg/cfdg.js
COPY --from=cfdg /context-free/web/cfdg.js /cfdg/cfdg.js
RUN echo "self.CFDG = Module;" >> /cfdg/cfdg.js
#run echo "self.module = self.module || {};" >> /cfdg/cfdg.cjs
#RUN echo "self.module.exports = Module;" >> /cfdg/cfdg.cjs
COPY ./cfdg/package.json /cfdg
COPY ./cfdg/cfdg.d.ts /cfdg

RUN npm link /cfdg

COPY craco.config.js .

COPY vite.config.ts .
COPY tsconfig.json .
COPY tsconfig.app.json .
COPY tsconfig.node.json .
COPY index.html .
COPY ./public ./public
COPY ./src ./src
RUN npm run build
Expand Down
96 changes: 50 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
# 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 tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
1 change: 1 addition & 0 deletions cfdg/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "cfdg",
"type": "commonjs",
"files": [
"cfdg.js",
"cfdg.d.ts"
Expand Down
13 changes: 0 additions & 13 deletions craco.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if [ "$DEV" == "1" ]
then
exec npm start
exec npm run dev -- --port 3000 --host
else
exec serve build
exec npm run preview -- --port 3000 --host
fi
28 changes: 28 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Inconsolata:[email protected]&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<title>Vite + React + TS</title>
</head>
<body>
<div id="root" style="width:100%;height:100%"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit e87b68a

Please sign in to comment.