Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed Jul 19, 2023
1 parent 39dc824 commit a014fb5
Show file tree
Hide file tree
Showing 45 changed files with 5,037 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check=true
strict-peer-dependencies=false
3 changes: 3 additions & 0 deletions .vscode/setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pkg

[![NPM version](https://img.shields.io/npm/v/pkg?color=a1b858&label=)](https://www.npmjs.com/package/pkg)
[![NPM version](https://img.shields.io/npm/v/vite-react-ssg?color=a1b858&label=)](https://www.npmjs.com/package/vite-react-ssg)

## License

Expand Down
3 changes: 3 additions & 0 deletions bin/vite-react-ssg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict'
import('../dist/node/cli.mjs')
12 changes: 11 additions & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
{ input: 'src/index', name: 'index' },
{ input: 'src/node/cli', name: 'node/cli' },
{ input: 'src/node', name: 'node' },
],
declaration: true,
clean: true,
externals: [
'react',
'react-dom',
'react-dom/server',
'react-router-dom',
'react-router-dom/server',
],
rollup: {
emitCJS: true,
inlineDependencies: true,
},
})
7 changes: 7 additions & 0 deletions examples/multiple-pages/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */

module.exports = {
extends: [
'@ririd',
],
}
24 changes: 24 additions & 0 deletions examples/multiple-pages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions examples/multiple-pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/multiple-pages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "multiple-pages",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:ssg": "vite-react-ssg build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "6.14.1"
},
"devDependencies": {
"@vitejs/plugin-react-swc": "^3.3.2",
"vite": "^4.4.0",
"vite-plugin-pages": "^0.31.0",
"vite-react-ssg": "workspace:*"
}
}
1 change: 1 addition & 0 deletions examples/multiple-pages/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions examples/multiple-pages/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
43 changes: 43 additions & 0 deletions examples/multiple-pages/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'
import { Layout } from './Layout'
import './App.css'
import Index from './pages'

// import A from './pages/a'

// export const routes = [
// {
// path: '/',
// element: React.lazy(() => import('./pages/index')),
// children: [
// {
// path: '/a',
// element: React.lazy(() => import('./pages/a')),
// },
// ],
// },

// ]
// const sleep = (n = 500) => new Promise(r => setTimeout(r, n))

export const routes = [
{
path: '/',
element: <Layout />,
children: [
{
index: true,
element: <Index />,
},
{
path: 'a',
Component: React.lazy(async () => {
// await sleep(3000)
return import('./pages/a')
}),
},
],
},
]

// export const router = createBrowserRouter(routes)
21 changes: 21 additions & 0 deletions examples/multiple-pages/src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Suspense } from 'react'
import { Outlet } from 'react-router-dom'

export function Layout() {
return (
<>

Check failure on line 6 in examples/multiple-pages/src/Layout.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
{/* <Head>
<meta charSet="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>head test</title>
</Head> */}
<main>

Check failure on line 13 in examples/multiple-pages/src/Layout.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<h1>Layout</h1>

Check failure on line 14 in examples/multiple-pages/src/Layout.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<Suspense>

Check failure on line 15 in examples/multiple-pages/src/Layout.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<Outlet />

Check failure on line 16 in examples/multiple-pages/src/Layout.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
</Suspense>
</main>
</>
)
}
1 change: 1 addition & 0 deletions examples/multiple-pages/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions examples/multiple-pages/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
10 changes: 10 additions & 0 deletions examples/multiple-pages/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ViteReactSSG } from 'vite-react-ssg'
import { routes } from './App.js'
import './index.css'

export const createApp = ViteReactSSG({ routes })

// export const createApp = ViteReactSSG(
// <App />,
// routes,
// )
3 changes: 3 additions & 0 deletions examples/multiple-pages/src/pages/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
color: red;
}
12 changes: 12 additions & 0 deletions examples/multiple-pages/src/pages/a.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useNavigate } from 'react-router-dom'
import './a.css'

export default function A() {
const navigate = useNavigate()
return (
<>

Check failure on line 7 in examples/multiple-pages/src/pages/a.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<h1 className="a">Page A</h1>

Check failure on line 8 in examples/multiple-pages/src/pages/a.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<button onClick={() => navigate('/')}>to index</button>

Check failure on line 9 in examples/multiple-pages/src/pages/a.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
</>
)
}
30 changes: 30 additions & 0 deletions examples/multiple-pages/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useState } from 'react'
import { Link, useNavigate } from 'react-router-dom'

export default function Index() {
const [count, setCount] = useState(0)
const navigate = useNavigate()

return (
<>

Check failure on line 9 in examples/multiple-pages/src/pages/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
<div>

Check failure on line 10 in examples/multiple-pages/src/pages/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount(count => count + 1)}>
count is {count}
</button>
<button onClick={() => navigate('/a')}>
to A
</button>
<Link to={'/a'}>TO A</Link>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}
15 changes: 15 additions & 0 deletions examples/multiple-pages/src/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

export const routes = [
{
path: '/',
element: React.lazy(() => import('./pages/index')),
children: [
{
path: '/a',
element: React.lazy(() => import('./pages/a')),
},
],
},

]
1 change: 1 addition & 0 deletions examples/multiple-pages/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading

0 comments on commit a014fb5

Please sign in to comment.