-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from jkirkpatrick24/feat/spa-config
feat: simplify configuration for SPA applications
- Loading branch information
Showing
12 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
parser: '@babel/eslint-parser', | ||
parserOptions: { | ||
requireConfigFile: false, | ||
ecmaVersion: 2021, | ||
sourceType: 'module', | ||
babelOptions: { | ||
presets: ['@babel/preset-react'], | ||
}, | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
extends: [ | ||
'plugin:react/recommended', | ||
'standard', | ||
], | ||
plugins: [ | ||
'react', | ||
], | ||
rules: { | ||
'comma-dangle': ['error', 'always-multiline'], | ||
'react/prop-types': 'off', | ||
'import/no-absolute-path': 'off', | ||
}, | ||
settings: { | ||
react: { | ||
version: '18.0', | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
|
||
export function createApp () { | ||
return ( | ||
<p>Hello world from React and @fastify/vite!</p> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<main><!-- element --></main> | ||
<script type="module" src="/mount.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createRoot } from 'react-dom/client' | ||
import { createApp } from './base.jsx' | ||
|
||
const root = createRoot(document.querySelector('main')) | ||
root.render(createApp()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"type": "module", | ||
"scripts": { | ||
"dev": "node server.js --dev", | ||
"devinstall": "zx ../../devinstall.mjs react-vanilla -- node server.js --dev", | ||
"build": "vite build --outDir dist/client", | ||
"lint": "eslint . --ext .js,.jsx --fix", | ||
"test": "vitest run" | ||
}, | ||
"dependencies": { | ||
"react-dom": "^18.1.0", | ||
"fastify": "^4.7.0", | ||
"vite": "^3.1.6", | ||
"@fastify/static": "^6.5.0", | ||
"fs-extra": "^10.0.0", | ||
"klaw": "^4.0.1", | ||
"middie": "^5.2.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/eslint-parser": "^7.16.0", | ||
"@babel/preset-react": "^7.16.0", | ||
"@vitejs/plugin-react": "^1.3.2", | ||
"eslint": "^7.32.0", | ||
"eslint-config-standard": "^16.0.2", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.3.1", | ||
"eslint-plugin-react": "^7.29.4" | ||
}, | ||
"devInstall": { | ||
"local": { | ||
"@fastify/vite": "^3.0.1" | ||
}, | ||
"external": { | ||
"react-dom": "^18.1.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Fastify from 'fastify' | ||
import FastifyVite from '@fastify/vite' | ||
|
||
export async function main (dev) { | ||
const server = Fastify() | ||
|
||
await server.register(FastifyVite, { | ||
root: import.meta.url, | ||
dev: dev ?? process.argv.includes('--dev'), | ||
spa: true, | ||
}) | ||
|
||
server.get('/', (req, reply) => { | ||
reply.html() | ||
}) | ||
|
||
await server.vite.ready() | ||
return server | ||
} | ||
|
||
if (process.argv[1] === new URL(import.meta.url).pathname) { | ||
const server = await main() | ||
await server.listen({ port: 3000 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { test } from 'vitest' | ||
import { makeIndexTest } from '../../testing.js' | ||
import { main } from './server.js' | ||
|
||
test('render index page in development', makeIndexTest({ main, dev: true })) | ||
test('render index page in production', makeIndexTest({ main })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { resolve, dirname } from 'path' | ||
import viteReact from '@vitejs/plugin-react' | ||
|
||
const path = new URL(import.meta.url).pathname | ||
const root = resolve(dirname(path), 'client') | ||
|
||
const plugins = [ | ||
viteReact({ jsxRuntime: 'classic' }), | ||
] | ||
|
||
export default { | ||
root, | ||
plugins, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { dirname } from 'node:path' | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
root: dirname(new URL(import.meta.url).pathname), | ||
test: { | ||
testTimeout: 15000, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters