Try using esbuild bundle option.

This commit is contained in:
Dillon Kearns 2022-07-05 10:58:00 -07:00
parent bdc1715726
commit 343b30bc3a
3 changed files with 15 additions and 14 deletions

View File

@ -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];

View File

@ -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: [
{

View File

@ -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
}
}
`,
});
}