Skip to content

Commit cd86341

Browse files
committed
Init browser generator
1 parent 97c87c7 commit cd86341

24 files changed

+557
-0
lines changed

tools/templates/generators.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"generators": {
3+
"browser": {
4+
"factory": "./src/generators/browser/generator",
5+
"schema": "./src/generators/browser/schema.json",
6+
"description": "browser generator"
7+
},
38
"nodejs": {
49
"factory": "./src/generators/nodejs/generator",
510
"schema": "./src/generators/nodejs/schema.json",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:react-hooks/recommended',
8+
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['react-refresh'],
12+
rules: {
13+
'react-refresh/only-export-components': [
14+
'warn',
15+
{ allowConstantExport: true },
16+
],
17+
},
18+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
.env
11+
node_modules
12+
dist
13+
dist-ssr
14+
*.local
15+
16+
# Editor directories and files
17+
.vscode/*
18+
!.vscode/extensions.json
19+
.idea
20+
.DS_Store
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://json.schemastore.org/mocharc.json",
3+
"require": "tsx"
4+
}

tools/templates/src/generators/browser/files/README.md

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
<style>
9+
body,
10+
html {
11+
margin: 0;
12+
height: 100%;
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
}
17+
#root {
18+
width: 100%;
19+
text-align: center;
20+
}
21+
</style>
22+
</head>
23+
<body>
24+
<div id="root"></div>
25+
<script type="module" src="/src/main.tsx"></script>
26+
</body>
27+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "<%= name.replace(/\//g, '-') %>",
3+
"version": "0.1.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "vite",
9+
"build": "tsc -b && vite build",
10+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
11+
"preview": "vite preview"
12+
},
13+
"dependencies": {
14+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
15+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
16+
"@vitejs/plugin-react-swc": "^3.7.0",
17+
"react": "^18.3.1",
18+
"react-dom": "^18.3.1",
19+
"rollup-plugin-polyfill-node": "^0.13.0",
20+
"vite-plugin-node-polyfills": "^0.22.0"
21+
},
22+
"devDependencies": {
23+
"@types/react": "^18.3.3",
24+
"@types/react-dom": "^18.3.0",
25+
"@typescript-eslint/eslint-plugin": "^7.13.1",
26+
"@typescript-eslint/parser": "^7.13.1",
27+
"@vitejs/plugin-react": "^4.3.1",
28+
"eslint": "^8.57.0",
29+
"eslint-plugin-react-hooks": "^4.6.2",
30+
"eslint-plugin-react-refresh": "^0.4.7",
31+
"typescript": "^5.5.3",
32+
"vite": "^5.3.1"
33+
}
34+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { runExample } from './litCode';
2+
3+
function App() {
4+
return (
5+
<>
6+
<div className="card">
7+
<hr />
8+
<h3>Browser Example</h3>
9+
<button onClick={async () => await runExample()}>
10+
Run the example
11+
</button>
12+
</div>
13+
</>
14+
);
15+
}
16+
17+
export default App;
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
:root {
2+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3+
line-height: 1.5;
4+
font-weight: 400;
5+
6+
color-scheme: light dark;
7+
color: rgba(255, 255, 255, 0.87);
8+
background-color: #242424;
9+
10+
font-synthesis: none;
11+
text-rendering: optimizeLegibility;
12+
-webkit-font-smoothing: antialiased;
13+
-moz-osx-font-smoothing: grayscale;
14+
}
15+
16+
a {
17+
font-weight: 500;
18+
color: #646cff;
19+
text-decoration: inherit;
20+
}
21+
a:hover {
22+
color: #535bf2;
23+
}
24+
25+
body {
26+
margin: 0;
27+
display: flex;
28+
place-items: center;
29+
min-width: 320px;
30+
min-height: 100vh;
31+
}
32+
33+
h1 {
34+
font-size: 3.2em;
35+
line-height: 1.1;
36+
}
37+
38+
button {
39+
border-radius: 8px;
40+
border: 1px solid transparent;
41+
padding: 0.6em 1.2em;
42+
font-size: 1em;
43+
font-weight: 500;
44+
font-family: inherit;
45+
background-color: #1a1a1a;
46+
cursor: pointer;
47+
transition: border-color 0.25s;
48+
}
49+
button:hover {
50+
border-color: #646cff;
51+
}
52+
button:focus,
53+
button:focus-visible {
54+
outline: 4px auto -webkit-focus-ring-color;
55+
}
56+
57+
@media (prefers-color-scheme: light) {
58+
:root {
59+
color: #213547;
60+
background-color: #ffffff;
61+
}
62+
a:hover {
63+
color: #747bff;
64+
}
65+
button {
66+
background-color: #f9f9f9;
67+
}
68+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const runExample = async () => {
2+
try {
3+
} catch (error) {
4+
console.error(error);
5+
} finally {
6+
// Disconnect from LitNodeClient, etc.
7+
}
8+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import App from './App.tsx';
4+
import './index.css';
5+
6+
ReactDOM.createRoot(document.getElementById('root')!).render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>
10+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
5+
"target": "ES2020",
6+
"useDefineForClassFields": true,
7+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
8+
"module": "ESNext",
9+
"skipLibCheck": true,
10+
11+
/* Bundler mode */
12+
"moduleResolution": "bundler",
13+
"allowImportingTsExtensions": true,
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"moduleDetection": "force",
17+
"noEmit": true,
18+
"jsx": "react-jsx",
19+
20+
/* Linting */
21+
"strict": true,
22+
"noUnusedLocals": true,
23+
"noUnusedParameters": true,
24+
"noFallthroughCasesInSwitch": true
25+
},
26+
"include": ["src"]
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./tsconfig.app.json"
6+
},
7+
{
8+
"path": "./tsconfig.node.json"
9+
}
10+
]
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
5+
"skipLibCheck": true,
6+
"module": "ESNext",
7+
"moduleResolution": "bundler",
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"noEmit": true
11+
},
12+
"include": ["vite.config.ts"]
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineConfig } from 'vite';
2+
import react from '@vitejs/plugin-react';
3+
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
4+
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
5+
import rollupNodePolyFill from 'rollup-plugin-polyfill-node';
6+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
7+
8+
export default defineConfig({
9+
plugins: [
10+
react(),
11+
nodePolyfills({
12+
include: ['buffer', 'process', 'util'],
13+
}),
14+
],
15+
define: {
16+
'process.env': {},
17+
global: 'globalThis',
18+
},
19+
resolve: {
20+
alias: {
21+
// Remove the buffer alias
22+
},
23+
},
24+
optimizeDeps: {
25+
esbuildOptions: {
26+
define: {
27+
global: 'globalThis',
28+
},
29+
plugins: [
30+
NodeGlobalsPolyfillPlugin({
31+
buffer: true,
32+
process: true,
33+
}),
34+
NodeModulesPolyfillPlugin(),
35+
],
36+
},
37+
},
38+
build: {
39+
rollupOptions: {
40+
plugins: [rollupNodePolyFill()],
41+
},
42+
},
43+
});

0 commit comments

Comments
 (0)