| 115 | } |
| 116 | |
| 117 | async function buildApp( |
| 118 | appDir: string, |
| 119 | appName: string, |
| 120 | enableCityServer: boolean, |
| 121 | ) { |
| 122 | const optimizer = await import("@builder.io/qwik/optimizer"); |
| 123 | const appSrcDir = join(appDir, "src"); |
| 124 | const appDistDir = join(appDir, "dist"); |
| 125 | const appServerDir = join(appDir, "server"); |
| 126 | const basePath = `/${appName}/`; |
| 127 | const isProd = appName.includes(".prod"); |
| 128 | |
| 129 | // always clean the build directory |
| 130 | removeDir(appDistDir); |
| 131 | removeDir(appServerDir); |
| 132 | |
| 133 | let clientManifest: QwikManifest | undefined = undefined; |
| 134 | const plugins: PluginOption[] = []; |
| 135 | if (enableCityServer) { |
| 136 | // ssr entry existed in service folder, use dev plugin to |
| 137 | // 1. export router |
| 138 | // 2. set basePath |
| 139 | plugins.push({ |
| 140 | name: "devPlugin", |
| 141 | resolveId(id) { |
| 142 | if (id.endsWith(qwikCityVirtualEntry)) { |
| 143 | return qwikCityVirtualEntry; |
| 144 | } |
| 145 | if (id === qwikCityStaticPaths || id === qwikCityNotFoundPaths) { |
| 146 | return "./" + id; |
| 147 | } |
| 148 | }, |
| 149 | load(id) { |
| 150 | if (id.endsWith(qwikCityVirtualEntry)) { |
| 151 | return `import { createQwikCity } from '@builder.io/qwik-city/middleware/node'; |
| 152 | import qwikCityPlan from '@qwik-city-plan'; |
| 153 | import render from '${escapeChars(resolve(appSrcDir, "entry.ssr"))}'; |
| 154 | const { router, notFound } = createQwikCity({ |
| 155 | render, |
| 156 | qwikCityPlan, |
| 157 | base: '${basePath}build/', |
| 158 | }); |
| 159 | export { |
| 160 | router, |
| 161 | notFound |
| 162 | } |
| 163 | `; |
| 164 | } |
| 165 | if (id.endsWith(qwikCityStaticPaths)) { |
| 166 | return `export function isStaticPath(method, url){ return false; };`; |
| 167 | } |
| 168 | if (id.endsWith(qwikCityNotFoundPaths)) { |
| 169 | const notFoundHtml = getErrorHtml(404, "Resource Not Found"); |
| 170 | return `export function getNotFound(){ return ${JSON.stringify( |
| 171 | notFoundHtml, |
| 172 | )}; };`; |
| 173 | } |
| 174 | }, |