Skip to content

Commit c7b52ee

Browse files
committed
refactor(qwik dev): don't override Vite devserver
this applies to CSR projects. It makes the code simpler and along with Vite's expectations. It is done with the transformIndexHtml hook. Also: - build the optimizer using vite - compile the dev helper scripts - make CSR projects start at /index.html. A starter is provided for this - remove mentions of entry.dev.tsx
1 parent 0a30620 commit c7b52ee

32 files changed

+667
-1150
lines changed

packages/docs/src/routes/api/qwik-optimizer/api.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,6 @@
542542
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts",
543543
"mdFile": "core.qwikvite.md"
544544
},
545-
{
546-
"name": "QwikViteDevResponse",
547-
"id": "qwikvitedevresponse",
548-
"hierarchy": [
549-
{
550-
"name": "QwikViteDevResponse",
551-
"id": "qwikvitedevresponse"
552-
}
553-
],
554-
"kind": "Interface",
555-
"content": "```typescript\nexport interface QwikViteDevResponse \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[\\_qwikEnvData?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, any&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[\\_qwikRenderResolve?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n() =&gt; void\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>",
556-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts",
557-
"mdFile": "core.qwikvitedevresponse.md"
558-
},
559545
{
560546
"name": "QwikVitePlugin",
561547
"id": "qwikviteplugin",

packages/docs/src/routes/api/qwik-optimizer/index.mdx

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,63 +2210,6 @@ any
22102210

22112211
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts)
22122212

2213-
## QwikViteDevResponse
2214-
2215-
```typescript
2216-
export interface QwikViteDevResponse
2217-
```
2218-
2219-
<table><thead><tr><th>
2220-
2221-
Property
2222-
2223-
</th><th>
2224-
2225-
Modifiers
2226-
2227-
</th><th>
2228-
2229-
Type
2230-
2231-
</th><th>
2232-
2233-
Description
2234-
2235-
</th></tr></thead>
2236-
<tbody><tr><td>
2237-
2238-
[\_qwikEnvData?](#)
2239-
2240-
</td><td>
2241-
2242-
</td><td>
2243-
2244-
Record&lt;string, any&gt;
2245-
2246-
</td><td>
2247-
2248-
_(Optional)_
2249-
2250-
</td></tr>
2251-
<tr><td>
2252-
2253-
[\_qwikRenderResolve?](#)
2254-
2255-
</td><td>
2256-
2257-
</td><td>
2258-
2259-
() =&gt; void
2260-
2261-
</td><td>
2262-
2263-
_(Optional)_
2264-
2265-
</td></tr>
2266-
</tbody></table>
2267-
2268-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts)
2269-
22702213
## QwikVitePlugin
22712214

22722215
This is the type of the "pre" Qwik Vite plugin. `qwikVite` actually returns a tuple of two plugins, but after Vite flattens them, you can find the plugin by name.

packages/docs/src/routes/docs/(qwik)/advanced/library/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ This will create a new folder called `my-library` with the following structure:
5252
│   │   │   └── counter.tsx
5353
│   │   └── logo
5454
│   │   └── logo.tsx
55-
│   ├── entry.dev.tsx
5655
│   ├── entry.ssr.tsx
5756
│   ├── index.ts
5857
│   └── root.tsx
@@ -126,7 +125,7 @@ export { Counter } from './components/counter/counter';
126125

127126
## Libraries are also Apps
128127

129-
The library starter is also a standalone Qwik app (without routing, nor Qwik Router), this is the reason why you will find `entry.dev.tsx`, `entry.ssr.tsx` and `root.tsx` files.
128+
The library starter is also a standalone Qwik app (without routing, nor Qwik Router), this is the reason why you will find the `entry.ssr.tsx` and `root.tsx` files.
130129

131130
Do not worry about them, they won't be part of the final library, but they are useful during development and testing, so you can test your components in a real Qwik app.
132131

packages/docs/src/routes/docs/(qwik)/advanced/vite/index.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ client?: {
109109
* Default `src/components/app/app.tsx`
110110
*/
111111
input?: string[] | string;
112-
/**
113-
* Entry input for client-side only development with hot-module reloading.
114-
* This is for Vite development only and does not use SSR.
115-
* Default `src/entry.dev.tsx`
116-
*/
117-
devInput?: string;
118112
/**
119113
* Output directory for the client build.
120114
* Default `dist`

packages/qwik-router/global.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ type SerializationStrategy = import('@qwik.dev/core/internal').SerializationStra
99
declare var qcAsyncRequestStore: AsyncStore | undefined;
1010
declare var _qwikActionsMap: Map<string, ActionInternal> | undefined;
1111

12-
/** @deprecated Will be removed in v3 */
13-
declare var __qwikCityNew: boolean | undefined;
14-
15-
declare var __qwikRouterNew: boolean | undefined;
16-
1712
type ExperimentalFeatures = import('@qwik.dev/core/optimizer').ExperimentalFeatures;
1813

1914
declare var __EXPERIMENTAL__: {

packages/qwik/src/devtools/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// @ts-expect-error compiled-string-plugin
21
export { default as devtoolsJsonSRC } from './json?compiled-string';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*?compiled-string' {
2+
const code: string;
3+
export default code;
4+
}

packages/qwik/src/optimizer/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ export type {
4141

4242
export type { ExperimentalFeatures, QwikBuildMode, QwikBuildTarget } from './plugins/plugin';
4343
export type { QwikRollupPluginOptions } from './plugins/rollup';
44-
export type {
45-
QwikViteDevResponse,
46-
QwikVitePlugin,
47-
QwikVitePluginApi,
48-
QwikVitePluginOptions,
49-
} from './plugins/vite';
44+
export type { QwikVitePlugin, QwikVitePluginApi, QwikVitePluginOptions } from './plugins/vite';
5045

5146
export type { BundleGraphAdder } from './plugins/bundle-graph';
5247

packages/qwik/src/optimizer/src/plugins/click-to-component.html renamed to packages/qwik/src/optimizer/src/plugins/dev/click-to-component.js

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,17 @@
1-
<style>
2-
#qwik-inspector-overlay {
3-
position: fixed;
4-
background: rgba(24, 182, 246, 0.27);
5-
pointer-events: none;
6-
box-sizing: border-box;
7-
border: 2px solid rgba(172, 126, 244, 0.46);
8-
border-radius: 4px;
9-
contain: strict;
10-
cursor: pointer;
11-
z-index: 999999;
12-
}
13-
14-
#qwik-inspector-info-popup {
15-
position: fixed;
16-
bottom: 10px;
17-
right: 10px;
18-
font-family: monospace;
19-
background: #000000c2;
20-
color: white;
21-
padding: 10px 20px;
22-
border-radius: 8px;
23-
box-shadow:
24-
0 20px 25px -5px rgb(0 0 0 / 34%),
25-
0 8px 10px -6px rgb(0 0 0 / 24%);
26-
backdrop-filter: blur(4px);
27-
-webkit-animation: fadeOut 0.3s 3s ease-in-out forwards;
28-
animation: fadeOut 0.3s 3s ease-in-out forwards;
29-
z-index: 999999;
30-
contain: layout;
31-
}
32-
33-
#qwik-inspector-info-popup p {
34-
margin: 0px;
35-
}
36-
37-
@-webkit-keyframes fadeOut {
38-
0% {
39-
opacity: 1;
40-
}
41-
42-
100% {
43-
opacity: 0;
44-
}
45-
}
46-
47-
@keyframes fadeOut {
48-
0% {
49-
opacity: 1;
50-
}
51-
52-
100% {
53-
opacity: 0;
54-
visibility: hidden;
55-
}
56-
}
57-
</style>
58-
<div id="qwik-inspector-info-popup" aria-hidden="true">Click-to-Source</div>
59-
<script>
60-
(function () {
1+
if (typeof document !== 'undefined') {
2+
const register = () => {
613
const inspectAttribute = 'data-qwik-inspector';
62-
const hotKeys = globalThis.qwikdevtools.hotKeys;
63-
const srcDir = globalThis.qwikdevtools.srcDir;
64-
document.querySelector('#qwik-inspector-info-popup').textContent =
65-
`Click-to-Source: ${hotKeys.join(' + ')}`;
4+
const hotKeys = globalThis.__HOTKEYS__;
5+
const srcDir = globalThis.__SRC_DIR__;
6+
let popup = document.querySelector('#qwik-inspector-info-popup');
7+
if (!popup) {
8+
popup = document.createElement('div');
9+
popup.id = 'qwik-inspector-info-popup';
10+
popup['aria-hidden'] = 'true';
11+
document.body.appendChild(popup);
12+
}
13+
popup.textContent = `Click-to-Source: ${hotKeys.join(' + ')}`;
14+
// eslint-disable-next-line no-console
6615
console.debug(
6716
'%c🔍 Qwik Click-To-Source',
6817
'background: #564CE0; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;',
@@ -107,7 +56,7 @@
10756

10857
window.addEventListener(
10958
'blur',
110-
(event) => {
59+
() => {
11160
window.__qwik_inspector_state.pressedKeys.clear();
11261
updateOverlay();
11362
},
@@ -139,14 +88,15 @@
13988
const inspectUrl = target.getAttribute(inspectAttribute);
14089
if (inspectUrl !== 'false') {
14190
body.style.setProperty('cursor', 'progress');
142-
qwikOpenInEditor(inspectUrl);
91+
globalThis.qwikOpenInEditor(inspectUrl);
14392
}
14493
}
14594
}
14695
},
14796
{ capture: true }
14897
);
14998

99+
// TODO use the vite dev URLs and translate in resolveId + use launch-editor from NPM
150100
globalThis.qwikOpenInEditor = function (path) {
151101
const isWindows = navigator.platform.includes('Win');
152102
const resolvedURL = new URL(path, isWindows ? origin : srcDir);
@@ -208,5 +158,7 @@
208158
}
209159
window.addEventListener('resize', updateOverlay);
210160
document.addEventListener('scroll', updateOverlay);
211-
})();
212-
</script>
161+
};
162+
163+
document.addEventListener('DOMContentLoaded', register);
164+
}

packages/qwik/src/optimizer/src/plugins/error-host.html renamed to packages/qwik/src/optimizer/src/plugins/dev/error-host.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
<script>
2-
document.addEventListener('qerror', (ev) => {
3-
const ErrorOverlay = customElements.get('vite-error-overlay');
4-
if (!ErrorOverlay) {
5-
return;
6-
}
7-
const err = ev.detail.error;
8-
const overlay = new ErrorOverlay(err);
9-
document.body.appendChild(overlay);
10-
});
11-
</script>
12-
<script>
13-
/**
14-
* Usage:
15-
*
16-
* <errored-host></errored-host>
17-
*/
1+
/**
2+
* Usage:
3+
*
4+
* <errored-host></errored-host>
5+
*/
6+
if (typeof HTMLElement !== 'undefined') {
187
class ErroredHost extends HTMLElement {
198
get _root() {
209
return this.shadowRoot || this;
2110
}
2211

2312
constructor() {
2413
super();
25-
const self = this;
2614

2715
this.state = {};
2816
if (!this.props) {
@@ -181,4 +169,14 @@
181169
}
182170

183171
customElements.define('errored-host', ErroredHost);
184-
</script>
172+
173+
document.addEventListener('qerror', (ev) => {
174+
const ErrorOverlay = customElements.get('vite-error-overlay');
175+
if (!ErrorOverlay) {
176+
return;
177+
}
178+
const err = ev.detail.error;
179+
const overlay = new ErrorOverlay(err);
180+
document.body.appendChild(overlay);
181+
});
182+
}

0 commit comments

Comments
 (0)