Skip to content

Commit

Permalink
Merge pull request #20 from siguici/main
Browse files Browse the repository at this point in the history
Fix #13: Add include and exclude options to filter entrypoints.
  • Loading branch information
thejackshelton authored Nov 14, 2023
2 parents a48fb94 + d6258d3 commit e09b18c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion apps/astro-demo/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ export default defineConfig({
adapter: node({
mode: "standalone",
}),
integrations: [qwik()],
integrations: [qwik({
exclude: [
"**/react/*",
"**/react-*",
]
})],
});
16 changes: 12 additions & 4 deletions libs/qwikdev-astro/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { build } from "vite";
import { build, createFilter, type FilterPattern } from "vite";
import { join, relative } from "node:path";
import { createInterface } from "node:readline";
import { qwikVite } from "@builder.io/qwik/optimizer";
Expand All @@ -8,7 +8,10 @@ import { getQwikLoaderScript } from "@builder.io/qwik/server";

import type { AstroConfig, AstroIntegration } from "astro";

export default function createIntegration(): AstroIntegration {
export type Options = Partial<{ include: FilterPattern, exclude: FilterPattern }>;

export default function createIntegration(options: Options = {}): AstroIntegration {
let filter = createFilter(options.include, options.exclude);
let distDir: string = "";
let entryDir: string = "";
let astroConfig: AstroConfig | null = null;
Expand All @@ -32,7 +35,7 @@ export default function createIntegration(): AstroIntegration {
astroConfig.root.pathname,
astroConfig.srcDir.pathname
);
entrypoints = getQwikEntrypoints(entryDir);
entrypoints = getQwikEntrypoints(entryDir, filter);
if ((await entrypoints).length !== 0) {
addRenderer({
name: "@qwikdev/astro",
Expand Down Expand Up @@ -138,11 +141,16 @@ async function crawlDirectory(dir: string): Promise<string[]> {
* We need to find the Qwik entrypoints so that the client build will run successfully.
*
*/
async function getQwikEntrypoints(dir: string): Promise<string[]> {
async function getQwikEntrypoints(dir: string, filter: (id: unknown) => boolean ): Promise<string[]> {
const files = await crawlDirectory(dir);
const qwikFiles = [];

for (const file of files) {
// Skip files not matching patterns
if (! filter(file)) {
continue;
}

const fileStream = createReadStream(file);

// holds readline interface
Expand Down

0 comments on commit e09b18c

Please sign in to comment.