-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: simplify configuration for SPA applications #94
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left this as /dist/client, but it may make sense to remove this hard dependency on having a /client folder. SPAs should probably just use the /dist output (or at least allow for configuration)
Any thoughts on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSYK There's no hard dependency on having a
client/
folder,root
invite.config.js
can be the same folder asserver.js
and it should work fine.Amazing work, I'll give it a go and review properly soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool thanks!
What I meant here was that AFAICT, the output folder has to be /client right now for production. Unless there is a way of overriding how the production bundles are loaded that I missed.