Skip to content

Commit 83ff79d

Browse files
committed
chore(docs): fix several warnings etc
1 parent b5fbd8f commit 83ff79d

File tree

6 files changed

+64
-22
lines changed

6 files changed

+64
-22
lines changed

packages/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"scripts": {
7070
"build": "qwik build",
7171
"build.client": "vite build",
72-
"build.preview": "vite build --ssr src/entry.preview.tsx",
72+
"build.preview": "NODE_OPTIONS=--max-old-space-size=8192 vite build --ssr src/entry.preview.tsx",
7373
"build.repl-sw": "vite --config vite.config-repl-sw.mts build",
7474
"build.server": "NODE_OPTIONS=--max-old-space-size=8192 vite build -c adapters/cloudflare-pages/vite.config.mts",
7575
"build.showcase": "pnpm node scripts/showcase.js",

packages/docs/vite.config.mts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,54 @@ import { qwikInsights } from '@builder.io/qwik-labs/vite';
44
import { qwikReact } from '@builder.io/qwik-react/vite';
55
import { qwikVite } from '@builder.io/qwik/optimizer';
66
import path, { resolve } from 'node:path';
7-
import { defineConfig, loadEnv } from 'vite';
7+
import { defineConfig, loadEnv, type Plugin } from 'vite';
88
import Inspect from 'vite-plugin-inspect';
99
import { examplesData, playgroundData, rawSource, tutorialData } from './vite.repl-apps';
1010
import { sourceResolver } from './vite.source-resolver';
1111

1212
export const PUBLIC_QWIK_INSIGHT_KEY = loadEnv('', '.', 'PUBLIC').PUBLIC_QWIK_INSIGHTS_KEY;
1313
const docsDir = new URL(import.meta.url).pathname;
1414

15+
// https://github.com/vitejs/vite/issues/15012#issuecomment-1825035992
16+
const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => {
17+
const mutedMessages = new Set();
18+
return {
19+
name: 'mute-warnings',
20+
enforce: 'pre',
21+
config: (userConfig) => {
22+
const origOnLog = userConfig.build?.rollupOptions?.onLog;
23+
return {
24+
build: {
25+
rollupOptions: {
26+
onLog(type, warning, defaultHandler) {
27+
if (type === 'warn') {
28+
if (warning.code) {
29+
const muted = warningsToIgnore.find(
30+
([code, message]) => code == warning.code && warning.message.includes(message)
31+
);
32+
33+
if (muted) {
34+
mutedMessages.add(muted.join());
35+
return;
36+
}
37+
}
38+
}
39+
origOnLog ? origOnLog(type, warning, defaultHandler) : defaultHandler(type, warning);
40+
},
41+
},
42+
},
43+
};
44+
},
45+
closeBundle() {
46+
const diff = warningsToIgnore.filter((x) => !mutedMessages.has(x.join()));
47+
if (diff.length > 0) {
48+
this.warn('Some of your muted warnings never appeared during the build process:');
49+
diff.forEach((m) => this.warn(`- ${m.join(': ')}`));
50+
}
51+
},
52+
};
53+
};
54+
1555
export default defineConfig(async () => {
1656
const { default: rehypePrettyCode } = await import('rehype-pretty-code');
1757

@@ -58,6 +98,11 @@ export default defineConfig(async () => {
5898
},
5999

60100
plugins: [
101+
// some imported react code has sourcemap issues
102+
muteWarningsPlugin([
103+
['SOURCEMAP_ERROR', "Can't resolve original location of error"],
104+
['MODULE_LEVEL_DIRECTIVE', 'use client'],
105+
]),
61106
rawSource(),
62107
qwikCity({
63108
mdxPlugins: {
@@ -128,16 +173,6 @@ export default defineConfig(async () => {
128173
build: {
129174
sourcemap: true,
130175
rollupOptions: {
131-
// For some unknown reason, types don't work from tsc
132-
// Try removing these any casts and see if it works
133-
onLog(level: any, log: any, defaultHandler: any) {
134-
if (level == 'warn' && log.code === 'MODULE_LEVEL_DIRECTIVE') {
135-
// Suppress errors like these:
136-
// FILE Module level directives cause errors when bundled, "use client" in FILE was ignored.
137-
return;
138-
}
139-
defaultHandler(level, log);
140-
},
141176
output: {
142177
assetFileNames: 'assets/[hash]-[name].[ext]',
143178
},

packages/qwik-city/src/buildtime/vite/image-jsx.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,28 @@ export function imagePlugin(userOpts?: QwikCityVitePluginOptions): PluginOption[
8888
this.error(`Image '${id}' could not be optimized to JSX`);
8989
}
9090
const index = code.indexOf('export default');
91-
return (
92-
code.slice(0, index) +
93-
`
91+
return {
92+
code:
93+
code.slice(0, index) +
94+
`
9495
import { _jsxQ } from '@builder.io/qwik';
9596
const PROPS = {srcSet, width, height};
9697
export default function (props, key, _, dev) {
9798
return _jsxQ('img', {...{decoding: 'async', loading: 'lazy'}, ...props}, PROPS, undefined, 3, key, dev);
98-
}`
99-
);
99+
}`,
100+
map: null,
101+
};
100102
} else if (extension === '.svg') {
101103
const { svgAttributes } = optimizeSvg({ code, path: pathId }, userOpts);
102-
return `
104+
return {
105+
code: `
103106
import { _jsxQ } from '@builder.io/qwik';
104107
const PROPS = ${JSON.stringify(svgAttributes)};
105108
export default function (props, key, _, dev) {
106109
return _jsxQ('svg', props, PROPS, undefined, 3, key, dev);
107-
}`;
110+
}`,
111+
map: null,
112+
};
108113
}
109114
}
110115
return null;

packages/qwik-city/src/buildtime/vite/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
202202
const fileName = basename(id);
203203
if (isMenuFileName(fileName)) {
204204
const menuCode = await transformMenu(ctx.opts, id, code);
205-
return menuCode;
205+
return { code: menuCode, map: null };
206206
}
207207
if (mdxTransform) {
208208
try {

packages/qwik/src/optimizer/src/plugins/rollup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
3939
async options(inputOpts) {
4040
await qwikPlugin.init();
4141

42+
const origOnwarn = inputOpts.onwarn;
4243
inputOpts.onwarn = (warning, warn) => {
4344
if (warning.plugin === 'typescript' && warning.message.includes('outputToFilesystem')) {
4445
return;
4546
}
46-
warn(warning);
47+
origOnwarn ? origOnwarn(warning, warn) : warn(warning);
4748
};
4849

4950
const pluginOpts: QwikPluginOptions = {

packages/qwik/src/optimizer/src/plugins/vite.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
355355

356356
updatedViteConfig.build!.cssCodeSplit = false;
357357
updatedViteConfig.build!.outDir = buildOutputDir;
358+
const origOnwarn = updatedViteConfig.build!.rollupOptions?.onwarn;
358359
updatedViteConfig.build!.rollupOptions = {
359360
input: opts.input,
360361
output: normalizeRollupOutputOptions(
@@ -369,7 +370,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
369370
if (warning.plugin === 'typescript' && warning.message.includes('outputToFilesystem')) {
370371
return;
371372
}
372-
warn(warning);
373+
origOnwarn ? origOnwarn(warning, warn) : warn(warning);
373374
},
374375
};
375376

0 commit comments

Comments
 (0)