Skip to content

Commit 5c89ea1

Browse files
authored
Merge pull request #8063 from QwikDev/fix-v2-lib-starter-dev-mode-not-booting-up
fix: library starter dev mode not booting up & better types
2 parents 8b99246 + a772f63 commit 5c89ea1

File tree

7 files changed

+101
-22
lines changed

7 files changed

+101
-22
lines changed

starters/apps/library/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
"private": false,
66
"main": "./lib/index.qwik.mjs",
77
"qwik": "./lib/index.qwik.mjs",
8-
"types": "./lib-types/index.d.ts",
8+
"types": "./lib/index.d.ts",
99
"type": "module",
1010
"exports": {
1111
".": {
12+
"types": "./lib/index.d.ts",
1213
"import": "./lib/index.qwik.mjs",
13-
"require": "./lib/index.qwik.cjs",
14-
"types": "./lib-types/index.d.ts"
14+
"require": "./lib/index.qwik.cjs"
1515
}
1616
},
1717
"files": [
18-
"lib",
19-
"lib-types"
18+
"lib"
2019
],
2120
"scripts": {
2221
"build": "qwik build",
2322
"build.lib": "vite build --mode lib",
24-
"build.types": "tsc --emitDeclarationOnly",
23+
"build.types": "tsc -p tsconfig.types.json --emitDeclarationOnly --incremental false",
2524
"dev": "vite --mode ssr",
2625
"dev.debug": "node --inspect-brk ./node_modules/vite/bin/vite.js --mode ssr --force",
2726
"fmt": "prettier --write .",
@@ -34,6 +33,7 @@
3433
},
3534
"devDependencies": {
3635
"@qwik.dev/core": "latest",
36+
"@qwik.dev/router": "latest",
3737
"@eslint/js": "latest",
3838
"@types/node": "latest",
3939
"typescript-eslint": "latest",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* WHAT IS THIS FILE?
3+
*
4+
* SSR renderer function, used by Qwik Router.
5+
*
6+
* Note that this is the only place the Qwik renderer is called.
7+
* On the client, containers resume and do not call render.
8+
*/
9+
import { createRenderer } from "@qwik.dev/router";
10+
import Root from "./root";
11+
12+
export default createRenderer((opts) => {
13+
return {
14+
jsx: <Root />,
15+
options: {
16+
...opts,
17+
// Use container attributes to set attributes on the html tag.
18+
containerAttributes: {
19+
lang: "en-us",
20+
...opts.containerAttributes,
21+
},
22+
serverData: {
23+
...opts.serverData,
24+
// These are the default values for the document head and are overridden by the `head` exports
25+
// documentHead: {
26+
// title: "My App",
27+
// },
28+
},
29+
},
30+
};
31+
});

starters/apps/library/src/root.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
import { Counter } from "./components/counter/counter";
2-
import { Logo } from "./components/logo/logo";
1+
import { component$ } from "@qwik.dev/core";
2+
import {
3+
DocumentHeadTags,
4+
RouterOutlet,
5+
useLocation,
6+
useQwikRouter,
7+
} from "@qwik.dev/router";
8+
9+
import "./global.css";
10+
11+
export default component$(() => {
12+
useQwikRouter();
13+
const { url } = useLocation();
14+
15+
/**
16+
* This is the root of a QwikRouter site. It contains the document's `<head>` and `<body>`. You can adjust them as you see fit.
17+
*/
318

4-
export default () => {
519
return (
620
<>
721
<head>
822
<meta charset="utf-8" />
9-
<title>Qwik Library Starter</title>
23+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
24+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
25+
26+
<DocumentHeadTags />
27+
28+
<link rel="canonical" href={url.href} />
1029
</head>
1130
<body>
12-
<h1>Qwik Library Starter</h1>
13-
<p>
14-
This is a Qwik library starter. Make your components and export them
15-
from `src/index.ts`. This playground app will not be bundled with your
16-
library.
17-
</p>
18-
<Logo />
19-
<Counter />
31+
<RouterOutlet />
2032
</body>
2133
</>
2234
);
23-
};
35+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { component$ } from "@qwik.dev/core";
2+
import { Logo } from "../components/logo/logo";
3+
import { Counter } from "../components/counter/counter";
4+
5+
export default component$(() => {
6+
return (
7+
<>
8+
<h1>Qwik Library Starter</h1>
9+
<p>
10+
This is a playground meant for testing your library. Make your
11+
components and export them from `src/index.ts`. This playground app will
12+
not be bundled with your library. You can use the Router like a normal
13+
Qwik app with the Qwik Router.
14+
</p>
15+
<Logo />
16+
<Counter />
17+
</>
18+
);
19+
});

starters/apps/library/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"jsxImportSource": "@qwik.dev/core",
99
"strict": true,
1010
"declaration": true,
11-
"declarationDir": "lib-types",
11+
"declarationDir": "lib",
1212
"resolveJsonModule": true,
1313
"moduleResolution": "Bundler",
1414
"esModuleInterop": true,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"emitDeclarationOnly": true,
6+
"declarationDir": "lib",
7+
"noEmit": false
8+
},
9+
"exclude": [
10+
"src/routes/**",
11+
"src/root.tsx",
12+
"src/entry.ssr.tsx",
13+
"src/entry.dev.tsx"
14+
]
15+
}

starters/apps/library/vite.config.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { qwikVite } from "@qwik.dev/core/optimizer";
2+
import { qwikRouter } from "@qwik.dev/router/vite";
23
import { defineConfig } from "vite";
3-
import tsconfigPaths from "vite-tsconfig-paths";
44
import pkg from "./package.json";
5+
import tsconfigPaths from "vite-tsconfig-paths";
56

67
const { dependencies = {}, peerDependencies = {} } = pkg as any;
78
const makeRegex = (dep) => new RegExp(`^${dep}(/.*)?$`);
@@ -10,6 +11,7 @@ const excludeAll = (obj) => Object.keys(obj).map(makeRegex);
1011
export default defineConfig(() => {
1112
return {
1213
build: {
14+
outDir: "lib",
1315
target: "es2020",
1416
lib: {
1517
entry: "./src/index",
@@ -31,6 +33,6 @@ export default defineConfig(() => {
3133
],
3234
},
3335
},
34-
plugins: [qwikVite(), tsconfigPaths({ root: "." })],
36+
plugins: [qwikVite(), qwikRouter(), tsconfigPaths({ root: "." })],
3537
};
3638
});

0 commit comments

Comments
 (0)