Skip to content

Commit

Permalink
[docs] Fix SWC transform in vercel function (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mad-Kat authored Nov 22, 2024
1 parent 7791fb0 commit 2f8df60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/docs/app/api/transform/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import * as swc from "@swc/core";
// had to update package exports
// @ts-ignore
import cssLoader = require("next-yak/loaders/css-loader");
// import * as cssLoader from "next-yak/loaders/css-loader";
import path from "path";

export const maxDuration = 60;

const wasmPath = path.resolve(
process.cwd(),
"./node_modules",
"yak-swc/target/wasm32-wasi/release/yak_swc.wasm",
);

export async function POST(request: NextRequest) {
const code = (await request.json()) as Record<`file:///${string}`, string>;
Expand All @@ -23,7 +31,7 @@ export async function POST(request: NextRequest) {
filename: "/bar/index.tsx",
jsc: {
experimental: {
plugins: [["yak-swc", { basePath: "/foo/" }]],
plugins: [[wasmPath, { basePath: "/foo/" }]],
},
target: "es2022",
loose: false,
Expand Down
15 changes: 10 additions & 5 deletions packages/docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ const withMDX = createMDX();
const config = {
reactStrictMode: true,
experimental: {
optimizePackageImports: ["shiki", "@shikijs/monaco"],
optimizePackageImports: ["shiki", "@shikijs/monaco", "yak-swc"],
// serverComponentsExternalPackages: ["next-yak"],
},
outputFileTracingIncludes: {
// add yak-swc as a dependency for the /api/transform route
'/api/transform': ['./node_modules/yak-swc/*'],
'/api/transform': ['./node_modules/yak-swc/target/wasm32-wasi/release/*'],
},
outputFileTracingExcludes: {
'/api/transform': ['../../node_modules/yak-swc/**/*'],
},
// use the raw-loader for .d.ts files (used by the playground)
webpack: (config) => {
config.module.rules.push({
test: /\.d\.c?ts$/,
resourceQuery: /raw/,
use: "raw-loader",
// include: [
// path.resolve(process.cwd(), "node_modules"), // Allow importing from node_modules
// path.resolve(process.cwd()), // And from your source directory
// ],
});

return config;
Expand Down

0 comments on commit 2f8df60

Please sign in to comment.