From 343b30bc3a6a3aaebbdea7d45010a62ed95a8d88 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 5 Jul 2022 10:58:00 -0700 Subject: [PATCH] Try using esbuild bundle option. --- generator/src/build.js | 10 +++++----- generator/src/dev-server.js | 8 ++++---- generator/src/request-cache.js | 11 ++++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/generator/src/build.js b/generator/src/build.js index 2c6feb4a..4eabace5 100755 --- a/generator/src/build.js +++ b/generator/src/build.js @@ -138,15 +138,15 @@ async function run(options) { const portDataSourceCompiled = esbuild .build({ entryPoints: ["./port-data-source"], - outfile: ".elm-pages/compiled-ports/port-data-source.mjs", + platform: "node", + outfile: ".elm-pages/compiled-ports/port-data-source.js", assetNames: "[name]-[hash]", chunkNames: "chunks/[name]-[hash]", - outExtension: { ".js": ".mjs" }, - + outExtension: { ".js": ".js" }, metafile: true, - bundle: false, + bundle: true, watch: false, - logLevel: "silent", + logLevel: "error", }) .then((result) => { global.portsFilePath = Object.keys(result.metafile.outputs)[0]; diff --git a/generator/src/dev-server.js b/generator/src/dev-server.js index 185ec4fe..d45fa042 100644 --- a/generator/src/dev-server.js +++ b/generator/src/dev-server.js @@ -140,15 +140,15 @@ async function start(options) { .build({ entryPoints: ["./port-data-source"], entryNames: "[dir]/[name]-[hash]", - + platform: "node", outdir: ".elm-pages/compiled-ports", assetNames: "[name]-[hash]", chunkNames: "chunks/[name]-[hash]", - outExtension: { ".js": ".mjs" }, - logLevel: "silent", + outExtension: { ".js": ".js" }, + logLevel: "error", metafile: true, - bundle: false, + bundle: true, watch: true, plugins: [ { diff --git a/generator/src/request-cache.js b/generator/src/request-cache.js index 52513150..af5c181f 100644 --- a/generator/src/request-cache.js +++ b/generator/src/request-cache.js @@ -45,7 +45,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess) { const { fs } = require("./request-cache-fs.js")(hasFsAccess); return new Promise(async (resolve, reject) => { const request = toRequest(rawRequest); - const portsHash = (portsFile && portsFile.match(/-([^-]+)\.mjs$/)[1]) || ""; + const portsHash = (portsFile && portsFile.match(/-([^-]+)\.js$/)[1]) || ""; const responsePath = fullPath(portsHash, request, hasFsAccess); // TODO check cache expiration time and delete and go to else if expired @@ -56,12 +56,13 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess) { let portDataSource = {}; let portDataSourceImportError = null; try { - if (portsFile === undefined) { - throw "missing" + if (portsFile === undefined) { + throw "missing"; } const portDataSourcePath = path.resolve(portsFile); // On Windows, we need cannot use paths directly and instead must use a file:// URL. - portDataSource = await import(url.pathToFileURL(portDataSourcePath).href); + // portDataSource = await require(url.pathToFileURL(portDataSourcePath).href); + portDataSource = require(portDataSourcePath); } catch (e) { portDataSourceImportError = e; } @@ -152,7 +153,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess) { .yellow() .underline(request.url)} Bad HTTP response ${response.status} ${ response.statusText - } + } `, }); }