Skip to content

Commit

Permalink
chore(docs): fix several warnings etc
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Aug 5, 2024
1 parent b5fbd8f commit 83ff79d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"scripts": {
"build": "qwik build",
"build.client": "vite build",
"build.preview": "vite build --ssr src/entry.preview.tsx",
"build.preview": "NODE_OPTIONS=--max-old-space-size=8192 vite build --ssr src/entry.preview.tsx",
"build.repl-sw": "vite --config vite.config-repl-sw.mts build",
"build.server": "NODE_OPTIONS=--max-old-space-size=8192 vite build -c adapters/cloudflare-pages/vite.config.mts",
"build.showcase": "pnpm node scripts/showcase.js",
Expand Down
57 changes: 46 additions & 11 deletions packages/docs/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,54 @@ import { qwikInsights } from '@builder.io/qwik-labs/vite';
import { qwikReact } from '@builder.io/qwik-react/vite';
import { qwikVite } from '@builder.io/qwik/optimizer';
import path, { resolve } from 'node:path';
import { defineConfig, loadEnv } from 'vite';
import { defineConfig, loadEnv, type Plugin } from 'vite';
import Inspect from 'vite-plugin-inspect';
import { examplesData, playgroundData, rawSource, tutorialData } from './vite.repl-apps';
import { sourceResolver } from './vite.source-resolver';

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

// https://github.com/vitejs/vite/issues/15012#issuecomment-1825035992
const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => {
const mutedMessages = new Set();
return {
name: 'mute-warnings',
enforce: 'pre',
config: (userConfig) => {
const origOnLog = userConfig.build?.rollupOptions?.onLog;
return {
build: {
rollupOptions: {
onLog(type, warning, defaultHandler) {
if (type === 'warn') {
if (warning.code) {
const muted = warningsToIgnore.find(
([code, message]) => code == warning.code && warning.message.includes(message)
);

if (muted) {
mutedMessages.add(muted.join());
return;
}
}
}
origOnLog ? origOnLog(type, warning, defaultHandler) : defaultHandler(type, warning);
},
},
},
};
},
closeBundle() {
const diff = warningsToIgnore.filter((x) => !mutedMessages.has(x.join()));
if (diff.length > 0) {
this.warn('Some of your muted warnings never appeared during the build process:');
diff.forEach((m) => this.warn(`- ${m.join(': ')}`));
}
},
};
};

export default defineConfig(async () => {
const { default: rehypePrettyCode } = await import('rehype-pretty-code');

Expand Down Expand Up @@ -58,6 +98,11 @@ export default defineConfig(async () => {
},

plugins: [
// some imported react code has sourcemap issues
muteWarningsPlugin([
['SOURCEMAP_ERROR', "Can't resolve original location of error"],
['MODULE_LEVEL_DIRECTIVE', 'use client'],
]),
rawSource(),
qwikCity({
mdxPlugins: {
Expand Down Expand Up @@ -128,16 +173,6 @@ export default defineConfig(async () => {
build: {
sourcemap: true,
rollupOptions: {
// For some unknown reason, types don't work from tsc
// Try removing these any casts and see if it works
onLog(level: any, log: any, defaultHandler: any) {
if (level == 'warn' && log.code === 'MODULE_LEVEL_DIRECTIVE') {
// Suppress errors like these:
// FILE Module level directives cause errors when bundled, "use client" in FILE was ignored.
return;
}
defaultHandler(level, log);
},
output: {
assetFileNames: 'assets/[hash]-[name].[ext]',
},
Expand Down
19 changes: 12 additions & 7 deletions packages/qwik-city/src/buildtime/vite/image-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,28 @@ export function imagePlugin(userOpts?: QwikCityVitePluginOptions): PluginOption[
this.error(`Image '${id}' could not be optimized to JSX`);
}
const index = code.indexOf('export default');
return (
code.slice(0, index) +
`
return {
code:
code.slice(0, index) +
`
import { _jsxQ } from '@builder.io/qwik';
const PROPS = {srcSet, width, height};
export default function (props, key, _, dev) {
return _jsxQ('img', {...{decoding: 'async', loading: 'lazy'}, ...props}, PROPS, undefined, 3, key, dev);
}`
);
}`,
map: null,
};
} else if (extension === '.svg') {
const { svgAttributes } = optimizeSvg({ code, path: pathId }, userOpts);
return `
return {
code: `
import { _jsxQ } from '@builder.io/qwik';
const PROPS = ${JSON.stringify(svgAttributes)};
export default function (props, key, _, dev) {
return _jsxQ('svg', props, PROPS, undefined, 3, key, dev);
}`;
}`,
map: null,
};
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
const fileName = basename(id);
if (isMenuFileName(fileName)) {
const menuCode = await transformMenu(ctx.opts, id, code);
return menuCode;
return { code: menuCode, map: null };
}
if (mdxTransform) {
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
async options(inputOpts) {
await qwikPlugin.init();

const origOnwarn = inputOpts.onwarn;
inputOpts.onwarn = (warning, warn) => {
if (warning.plugin === 'typescript' && warning.message.includes('outputToFilesystem')) {
return;
}
warn(warning);
origOnwarn ? origOnwarn(warning, warn) : warn(warning);
};

const pluginOpts: QwikPluginOptions = {
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {

updatedViteConfig.build!.cssCodeSplit = false;
updatedViteConfig.build!.outDir = buildOutputDir;
const origOnwarn = updatedViteConfig.build!.rollupOptions?.onwarn;
updatedViteConfig.build!.rollupOptions = {
input: opts.input,
output: normalizeRollupOutputOptions(
Expand All @@ -369,7 +370,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
if (warning.plugin === 'typescript' && warning.message.includes('outputToFilesystem')) {
return;
}
warn(warning);
origOnwarn ? origOnwarn(warning, warn) : warn(warning);
},
};

Expand Down

0 comments on commit 83ff79d

Please sign in to comment.