-
-
Notifications
You must be signed in to change notification settings - Fork 124
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(router): support js/jsx extensions #636
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f9bd296
add non-working 02_template_js example
dai-shi a2fc2e0
remove types
dai-shi 32983f3
fix
dai-shi 2189ab3
wip: fs-router
dai-shi 7ca0bff
fix build
dai-shi bc980e9
fix
dai-shi 7f86aef
fix again
dai-shi e6c61c5
we should keep ext in glob
dai-shi 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,7 @@ | ||
node_modules | ||
dist | ||
.env* | ||
*.tsbuildinfo | ||
.cache | ||
.DS_Store | ||
*.pem |
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,21 @@ | ||
{ | ||
"name": "waku-starter", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "waku dev", | ||
"build": "waku build", | ||
"start": "waku start" | ||
}, | ||
"dependencies": { | ||
"react": "18.3.0-canary-670811593-20240322", | ||
"react-dom": "18.3.0-canary-670811593-20240322", | ||
"react-server-dom-webpack": "18.3.0-canary-670811593-20240322", | ||
"waku": "0.20.0" | ||
}, | ||
"devDependencies": { | ||
"autoprefixer": "10.4.19", | ||
"tailwindcss": "3.4.1" | ||
} | ||
} |
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 @@ | ||
/** @type {import('postcss-load-config').Config} */ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,21 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
|
||
export const Counter = () => { | ||
const [count, setCount] = useState(0); | ||
|
||
const handleIncrement = () => setCount((c) => c + 1); | ||
|
||
return ( | ||
<section className="border-blue-400 -mx-4 mt-4 rounded border border-dashed p-4"> | ||
<div>Count: {count}</div> | ||
<button | ||
onClick={handleIncrement} | ||
className="rounded-sm bg-black px-2 py-0.5 text-sm text-white" | ||
> | ||
Increment | ||
</button> | ||
</section> | ||
); | ||
}; |
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,18 @@ | ||
export const Footer = () => { | ||
return ( | ||
<footer className="p-6 lg:fixed lg:bottom-0 lg:left-0"> | ||
<div> | ||
visit{' '} | ||
<a | ||
href="https://waku.gg/" | ||
target="_blank" | ||
rel="noreferrer" | ||
className="mt-4 inline-block underline" | ||
> | ||
waku.gg | ||
</a>{' '} | ||
to learn more | ||
</div> | ||
</footer> | ||
); | ||
}; |
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,11 @@ | ||
import { Link } from 'waku'; | ||
|
||
export const Header = () => { | ||
return ( | ||
<header className="flex items-center gap-4 p-6 lg:fixed lg:left-0 lg:top-0"> | ||
<h2 className="text-lg font-bold tracking-tight"> | ||
<Link to="/">Waku starter</Link> | ||
</h2> | ||
</header> | ||
); | ||
}; |
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,35 @@ | ||
import '../styles.css'; | ||
|
||
import { Header } from '../components/header'; | ||
import { Footer } from '../components/footer'; | ||
|
||
export default async function RootLayout({ children }) { | ||
const data = await getData(); | ||
|
||
return ( | ||
<div className="font-['Nunito']"> | ||
<meta property="description" content={data.description} /> | ||
<link rel="icon" type="image/png" href={data.icon} /> | ||
<Header /> | ||
<main className="m-6 flex items-center *:min-h-64 *:min-w-64 lg:m-0 lg:min-h-svh lg:justify-center"> | ||
{children} | ||
</main> | ||
<Footer /> | ||
</div> | ||
); | ||
} | ||
|
||
const getData = async () => { | ||
const data = { | ||
description: 'An internet website!', | ||
icon: '/images/favicon.png', | ||
}; | ||
|
||
return data; | ||
}; | ||
|
||
export const getConfig = async () => { | ||
return { | ||
render: 'static', | ||
}; | ||
}; |
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,32 @@ | ||
import { Link } from 'waku'; | ||
|
||
export default async function AboutPage() { | ||
const data = await getData(); | ||
|
||
return ( | ||
<div> | ||
<title>{data.title}</title> | ||
<h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1> | ||
<p>{data.body}</p> | ||
<Link to="/" className="mt-4 inline-block underline"> | ||
Return home | ||
</Link> | ||
</div> | ||
); | ||
} | ||
|
||
const getData = async () => { | ||
const data = { | ||
title: 'About', | ||
headline: 'About Waku', | ||
body: 'The minimal React framework', | ||
}; | ||
|
||
return data; | ||
}; | ||
|
||
export const getConfig = async () => { | ||
return { | ||
render: 'static', | ||
}; | ||
}; |
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,35 @@ | ||
import { Link } from 'waku'; | ||
|
||
import { Counter } from '../components/counter'; | ||
|
||
export default async function HomePage() { | ||
const data = await getData(); | ||
|
||
return ( | ||
<div> | ||
<title>{data.title}</title> | ||
<h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1> | ||
<p>{data.body}</p> | ||
<Counter /> | ||
<Link to="/about" className="mt-4 inline-block underline"> | ||
About page | ||
</Link> | ||
</div> | ||
); | ||
} | ||
|
||
const getData = async () => { | ||
const data = { | ||
title: 'Waku', | ||
headline: 'Waku', | ||
body: 'Hello world!', | ||
}; | ||
|
||
return data; | ||
}; | ||
|
||
export const getConfig = async () => { | ||
return { | ||
render: 'static', | ||
}; | ||
}; |
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,4 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap'); | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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,4 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: ['./src/**/*.{js,jsx,ts,tsx}'], | ||
}; |
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import { fsRouter } from 'waku/router/server'; | ||
|
||
export default fsRouter(import.meta.url, loader); | ||
|
||
declare global { | ||
interface ImportMeta { | ||
readonly glob: any; | ||
} | ||
} | ||
|
||
function loader(dir: string, file: string) { | ||
const fname = `./${dir}/${file.replace(/\.\w+$/, '')}.tsx`; | ||
const modules = import.meta.glob('./pages/**/*.tsx'); | ||
return modules[fname](); | ||
} | ||
export default fsRouter(import.meta.url, (file: string) => | ||
import.meta.glob('./pages/**/*.tsx')[`./pages/${file}`]?.(), | ||
); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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 wish there would be a nice way to avoid it. But, maybe it's not a priority.