UNPKG

14.1 kBPlain TextView Raw
1{"code":"function iter$__(a){ let v; return a ? ((v=a.toIterable) ? v.call(a) : a) : a; };\nimport {createElement as imba_createElement, getRenderContext as imba_getRenderContext, createIndexedList as imba_createIndexedList, createComponent as imba_createComponent} from 'imba';\nvar $6 = Symbol(), $10 = Symbol(), $17 = Symbol(), $20 = Symbol(), $23 = Symbol(), $26 = Symbol(), $27 = Symbol(), $30 = Symbol(), $31 = Symbol(), $39 = Symbol(), $41 = Symbol(), $42 = Symbol(), $43 = Symbol(), $46 = Symbol();\nconst $$up$ = Symbol.for('##up'), $afterVisit$ = Symbol.for('#afterVisit'), $placeChild$ = Symbol.for('#placeChild'), $appendChild$ = Symbol.for('#appendChild');\n\n/*body*/\nimport path from \"path\";\nimport express from \"express\";\nimport compression from \"compression\";\nimport serveStatic from \"serve-static\";\nimport App from './src/App.imba';\nimport * as Vite from \"vite\";\nimport np from 'node:path';\nimport url from 'node:url';\n\nlet a = 1;\n// import moduleGraph from \"./server.moduleGraph.json\"\nconst _dirname = url.fileURLToPath(new URL('.',import.meta.url));;\n// We need to load SSR styles manually in order to prevent FOUC\n// We leverage vite-node to create a module graph from the server entry point\n// And we load all the tags CSS in separate files and concatenate them here\n// We didn't put them in one big css file because Vite transforms them to be\n// imported as ESModules so their string contain some js specific stuff\n// like \\n ... Instead we keep them to avoid breaking anything and import them\n// as they should be\nconst ssrΞcssΞmodules = import.meta.glob(\"./.ssr/*.css.js\");\nlet ssrΞstyles = \"\";\nfor (let $1 = 0, $2 = Object.keys(ssrΞcssΞmodules), $3 = $2.length, key; $1 < $3; $1++){\n\tkey = $2[$1];\n\tssrΞstyles += (await ssrΞcssΞmodules[key]()).default;\n};\nlet port = 3000;\nconst args = process.argv.slice(2);\nconst portArgPos = args.indexOf(\"--port\") + 1;\nif (portArgPos > 0) {\n\t\n\tport = parseInt(args[portArgPos],10);\n};\n\nasync function createServer(root = process.cwd(),isDev = import.meta.env.MODE === \"development\"){\n\t\n\tconst resolve = function(p) { return path.resolve(root,p); };\n\t\n\tlet manifest;\n\tif (!(isDev)) {\n\t\t\n\t\tmanifest = (await import(\"./dist_client/manifest.json\")).default;\n\t};\n\tconst app = express();\n\tconst configFile = np.join(_dirname,\"vite.config.mjs\");\n\tlet vite;\n\tif (isDev) {\n\t\t\n\t\tvite = await Vite.createServer(\n\t\t\t{root: root,\n\t\t\tappType: \"custom\",\n\t\t\tconfigFile: configFile,\n\t\t\tserver: {\n\t\t\t\tmiddlewareMode: true,\n\t\t\t\tport: port,\n\t\t\t\tstrictPort: true,\n\t\t\t\thmr: {\n\t\t\t\t\tport: port + 25000\n\t\t\t\t}\n\t\t\t}}\n\t\t);\n\t\tapp.use(vite.middlewares);\n\t} else {\n\t\t\n\t\tconst inlineCfg = {\n\t\t\troot: root,\n\t\t\tappType: \"custom\",\n\t\t\tserver: {\n\t\t\t\tmiddlewareMode: true\n\t\t\t}\n\t\t};\n\t\t// maybe use a different config\n\t\tapp.use(compression());\n\t\tapp.use(serveStatic(\"dist_client\",{index: false}));\n\t};\n\tapp.use(\"*\",function(req,res) {\n\t\tvar $14, $15, $16, $4, $5 = imba_getRenderContext(), $7, $8, $9, $11, $12, $13, $18, $19, $21, $22, $24, $25, $28, $29, $32, $33, $36, $37, $38, $44, $45, $47, $48;\n\t\t\n\t\tconst url = req.originalUrl;\n\t\ta++;\n\t\tconsole.log(\"%s %s %O\",'\u001b[90m::\u001b[0m','\u001b[44m\u001b[97ma\u001b[0m',a);\n\t\ttry {\n\t\t\t\n\t\t\tlet html = String((()=>{($7=$8=1,$4=$5[$6]) || ($7=$8=0,$4=$5[$6]=$4=imba_createElement('html',null,null,null));\n\t\t\t$7 || ($4[$$up$]=$5._);\n\t\t\t$7 || ($4.lang=\"en\");\n\t\t\t($9=$4[$10]) || ($4[$10]=$9=imba_createElement('head',$4,null,null));\n\t\t\t$7 || ($11=imba_createElement('meta',$9,null,null));\n\t\t\t$7 || ($11.charset=\"UTF-8\");\n\t\t\t;\n\t\t\t$7 || ($12=imba_createElement('meta',$9,null,null));\n\t\t\t$7 || ($12.name=\"viewport\");\n\t\t\t$7 || ($12.content=\"width=device-width, initial-scale=1.0\");\n\t\t\t;\n\t\t\t$7 || ($13=imba_createElement('title',$9,null,\"Imba App\"));\n\t\t\t;\n\t\t\t$14 = $15 = $16 = null;\n\t\t\tif (isDev) {\n\t\t\t\t\n\t\t\t\t($18=$19=1,$14=$4[$17]) || ($18=$19=0,$4[$17]=$14=imba_createElement('script',null,null,null));\n\t\t\t\t$18||($14[$$up$]=$9);\n\t\t\t\t$18 || ($14.type=\"module\");\n\t\t\t\t$18 || ($14.src=\"/@vite/client\");\n\t\t\t\t\n\t\t\t\t($21=$22=1,$15=$4[$20]) || ($21=$22=0,$4[$20]=$15=imba_createElement('script',null,null,null));\n\t\t\t\t$21||($15[$$up$]=$9);\n\t\t\t\t$21 || ($15.type=\"module\");\n\t\t\t\t$21 || ($15.src=\"/src/main.js\");\n\t\t\t\t\n\t\t\t\t($24=$25=1,$16=$4[$23]) || ($24=$25=0,$4[$23]=$16=imba_createElement('style',null,null,null));\n\t\t\t\t$24||($16[$$up$]=$9);\n\t\t\t\t$24 || ($16.id=\"dev_ssr_css\");\n\t\t\t\t(ssrΞstyles===$16[$26] || ($16.innerHTML=$16[$26]=ssrΞstyles));\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\t\n\t\t\t\tconst prodΞsrc = manifest[\"src/main.js\"].file;\n\t\t\t\tconst cssΞfiles = manifest[\"src/main.js\"].css;\n\t\t\t\t($28=$29=1,$14=$4[$27]) || ($28=$29=0,$4[$27]=$14=imba_createElement('script',null,null,null));\n\t\t\t\t$28||($14[$$up$]=$9);\n\t\t\t\t$28 || ($14.type=\"module\");\n\t\t\t\t(prodΞsrc===$14[$30] || ($14.src=$14[$30]=prodΞsrc));\n\t\t\t\t\n\t\t\t\t($15 = $4[$31]) || ($4[$31]=$15=imba_createIndexedList(0,null));\n\t\t\t\t$15[$$up$] = $9;\n\t\t\t\t$32 = 0;\n\t\t\t\t$33=$15.$;\n\t\t\t\tfor (let $34 = 0, $35 = iter$__(cssΞfiles), $40 = $35.length; $34 < $40; $34++) {\n\t\t\t\t\tlet cssΞfile = $35[$34];\n\t\t\t\t\t($37=$38=1,$36=$33[$32]) || ($37=$38=0,$33[$32]=$36=imba_createElement('style',$15,null,null));\n\t\t\t\t\t$37||($36[$$up$]=$15);\n\t\t\t\t\t(cssΞfile===$36[$39] || ($36.src=$36[$39]=cssΞfile));\n\t\t\t\t\t$32++;\n\t\t\t\t\t\n\t\t\t\t};$15[$afterVisit$]($32);\n\t\t\t};\n\t\t\t($4[$41] = $9[$placeChild$]($14,0,$4[$41]));\n\t\t\t($4[$42] = $9[$placeChild$]($15,0,$4[$42]));\n\t\t\t($4[$43] = $9[$placeChild$]($16,0,$4[$43]));\n\t\t\t;\n\t\t\t$7 || ($44=imba_createElement('body',$4,null,null));\n\t\t\t($47=$48=1,$45=$4[$46]) || ($47=$48=0,$4[$46]=$45=imba_createComponent(App,$44,null,null));\n\t\t\t$47 || !$45.setup || $45.setup($48);\n\t\t\t$45[$afterVisit$]($48);\n\t\t\t$47 || $44[$appendChild$]($45);\n\t\t\t;\n\t\t\t;\n\t\t\treturn $4;\n\t\t\t;})());\n\t\t\treturn res.status(200).set({\"Content-Type\": \"text/html\"}).end(html);\n\t\t} catch (e) {\n\t\t\t\n\t\t\tvite && vite.ssrFixStacktrace(e);\n\t\t\tconsole.log(\"err\",e.stack);\n\t\t\treturn res.status(500).end(e.stack);\n\t\t};\n\t});\n\treturn {app: app,\n\tvite: vite};\n};\n\nconst {app: app} = await createServer();\nconsole.log(\"server created\");\nconst server = app.listen(port,function() { return console.log((\"http://localhost:\" + port)); });\nconst exitProcess = async function() {\n\t\n\tconsole.log(\"exiting process\");\n\ttry {\n\t\treturn await server.close(function() { return console.log(\"server closed\"); });\n\t} finally {\n\t\tprocess.exit(0);\n\t};\n};\n\nprocess.stdin.on(\"end\",exitProcess);\n","map":{"version":3,"file":"server.js","sourceRoot":"","sources":["/Users/abdellah/workspace/scrimba/imba/temp/serve/vite-ssr-esm/server.imba"],"sourcesContent":["import path from \"path\"\nimport express from \"express\"\nimport compression from \"compression\"\nimport serveStatic from \"serve-static\"\nimport App from './src/App.imba'\nimport * as Vite from \"vite\"\nimport np from 'node:path'\nimport url from 'node:url'\n\nlet a = 1\n# import moduleGraph from \"./server.moduleGraph.json\"\nconst _dirname = url.fileURLToPath(new URL('.', import.meta.url));\n# We need to load SSR styles manually in order to prevent FOUC\n# We leverage vite-node to create a module graph from the server entry point\n# And we load all the tags CSS in separate files and concatenate them here\n# We didn't put them in one big css file because Vite transforms them to be\n# imported as ESModules so their string contain some js specific stuff\n# like \\n ... Instead we keep them to avoid breaking anything and import them\n# as they should be\nconst ssr-css-modules = import.meta.glob(\"./.ssr/*.css.js\")\nlet ssr-styles = \"\"\nfor own key of ssr-css-modules\n\tssr-styles += (await ssr-css-modules[key]()).default\nlet port = 3000\nconst args = process.argv.slice(2)\nconst portArgPos = args.indexOf(\"--port\") + 1\nif portArgPos > 0\n\tport = parseInt(args[portArgPos], 10)\n\ndef createServer(root = process.cwd(), isDev = import.meta.env.MODE === \"development\")\n\tconst resolve = do(p) path.resolve(root, p)\n\n\tlet manifest\\Object\n\tif !isDev\n\t\tmanifest = (await import(\"./dist_client/manifest.json\")).default\n\tconst app = express()\n\tconst configFile = np.join(_dirname, \"vite.config.mjs\")\n\tlet vite\n\tif isDev\n\t\tvite = await Vite.createServer\n\t\t\troot: root\n\t\t\tappType: \"custom\"\n\t\t\tconfigFile: configFile\n\t\t\tserver:\n\t\t\t\tmiddlewareMode: true\n\t\t\t\tport: port\n\t\t\t\tstrictPort: true\n\t\t\t\thmr:\n\t\t\t\t\tport: port + 25000\n\t\tapp.use vite.middlewares\n\telse\n\t\tconst inlineCfg = \n\t\t\troot: root\n\t\t\tappType: \"custom\"\n\t\t\tserver:\n\t\t\t\tmiddlewareMode: true\n\t\t# maybe use a different config\n\t\tapp.use compression()\n\t\tapp.use serveStatic(\"dist_client\", index: false)\n\tapp.use \"*\", do(req, res)\n\t\tconst url = req.originalUrl\n\t\ta++\n\t\tL a\n\t\ttry\n\t\t\tlet html = String <html lang=\"en\">\n\t\t\t\t<head>\n\t\t\t\t\t<meta charset=\"UTF-8\">\n\t\t\t\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t\t\t\t\t<title> \"Imba App\"\n\t\t\t\t\tif isDev\n\t\t\t\t\t\t<script type=\"module\" src=\"/@vite/client\">\n\t\t\t\t\t\t<script type=\"module\" src=\"/src/main.js\">\n\t\t\t\t\t\t<style id=\"dev_ssr_css\" innerHTML=ssr-styles>\n\t\t\t\t\telse\n\t\t\t\t\t\tconst prod-src = manifest[\"src/main.js\"].file\n\t\t\t\t\t\tconst css-files = manifest[\"src/main.js\"].css\n\t\t\t\t\t\t<script type=\"module\" src=prod-src>\n\t\t\t\t\t\tfor css-file in css-files\n\t\t\t\t\t\t\t<style src=css-file>\n\t\t\t\t<body>\n\t\t\t\t\t<App>\n\t\t\tres.status(200).set(\"Content-Type\": \"text/html\").end html\n\t\tcatch e\n\t\t\tvite and vite.ssrFixStacktrace(e)\n\t\t\tconsole.log \"err\", e.stack\n\t\t\tres.status(500).end e.stack\n\treturn\n\t\tapp: app\n\t\tvite: vite\n\nconst {app} = await createServer!\nconsole.log \"server created\"\nconst server = app.listen port, do console.log \"http://localhost:{port}\"\nconst exitProcess = do\n\tconsole.log \"exiting process\"\n\ttry await server.close do console.log \"server closed\" finally process.exit 0\n\nprocess.stdin.on \"end\", exitProcess\n"],"names":[],"mappings":";;;;;;AAAA,MAAM,CAAC,IAAI,MAAM,MAAM;AACvB,MAAM,CAAC,OAAO,MAAM,SAAS;AAC7B,MAAM,CAAC,WAAW,MAAM,aAAa;AACrC,MAAM,CAAC,WAAW,MAAM,cAAc;AACtC,MAAM,CAAC,GAAG,MAAM,gBAAgB;AAChC,MAAM,CAAC,CAAC,IAAI,IAAI,MAAM,MAAM;A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