Last active
March 30, 2023 08:24
-
-
Save repository/c92c99e097dec0d33c97c9e8b8cb17bc to your computer and use it in GitHub Desktop.
remix esbuild override patch (tested w/ @remix-run/dev 1.14.3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dist/compiler/compileBrowser.js b/dist/compiler/compileBrowser.js | |
index 7cd521547d7e408e906eb646deb0fff086577296..785d4b639f6e3a556408f57a8e01677936ca7bc0 100644 | |
--- a/dist/compiler/compileBrowser.js | |
+++ b/dist/compiler/compileBrowser.js | |
@@ -183,11 +183,15 @@ const createBrowserCompiler = (remixConfig, options) => { | |
let compile = async manifestChannel => { | |
hmrRoutes = {}; | |
let appBuildTask = async () => { | |
- appCompiler = await (!appCompiler ? esbuild__namespace.build({ | |
+ let esbuildConfig = { | |
...createEsbuildConfig("app", remixConfig, options, onLoader), | |
metafile: true, | |
incremental: true | |
- }) : appCompiler.rebuild()); | |
+ }; | |
+ | |
+ esbuildConfig = remixConfig.esbuildOverride(esbuildConfig); | |
+ | |
+ appCompiler = await (!appCompiler ? esbuild__namespace.build(esbuildConfig) : appCompiler.rebuild()); | |
invariant["default"](appCompiler.metafile, "Expected app compiler metafile to be defined. This is likely a bug in Remix. Please open an issue at https://github.com/remix-run/remix/issues/new"); | |
return appCompiler.metafile; | |
}; | |
diff --git a/dist/compiler/compilerServer.js b/dist/compiler/compilerServer.js | |
index 4d31adfdf0c70ea572c0f61d266d8f30ce0f579b..614d7a1d0e3545acffbe6d6215173cfdb4f842b0 100644 | |
--- a/dist/compiler/compilerServer.js | |
+++ b/dist/compiler/compilerServer.js | |
@@ -167,15 +167,18 @@ async function writeServerBuildResult(config, outputFiles) { | |
} | |
const createServerCompiler = (remixConfig, options) => { | |
let compile = async manifestChannel => { | |
- let esbuildConfig = createEsbuildConfig(remixConfig, manifestChannel, options); | |
+ let esbuildConfig = { | |
+ ...createEsbuildConfig(remixConfig, manifestChannel, options), | |
+ write: false, | |
+ metafile: true | |
+ }; | |
+ | |
+ esbuildConfig = remixConfig.esbuildOverride(esbuildConfig); | |
+ | |
let { | |
metafile, | |
outputFiles | |
- } = await esbuild__namespace.build({ | |
- ...esbuildConfig, | |
- write: false, | |
- metafile: true | |
- }); | |
+ } = await esbuild__namespace.build(esbuildConfig); | |
invariant["default"](metafile, "Expected metafile to be defined."); | |
await writeServerBuildResult(remixConfig, outputFiles); | |
return metafile; | |
diff --git a/dist/config.d.ts b/dist/config.d.ts | |
index 42f1e033d22b70ad1598b1588ae17ac1a65eb998..883375c4b2e0b56e0a536e4757c8d5a838b59d15 100644 | |
--- a/dist/config.d.ts | |
+++ b/dist/config.d.ts | |
@@ -1,5 +1,6 @@ | |
import type { RouteManifest, DefineRoutesFunction } from "./config/routes"; | |
import { ServerMode } from "./config/serverModes"; | |
+import type { BuildOptions } from "esbuild"; | |
export interface RemixMdxConfig { | |
rehypePlugins?: any[]; | |
remarkPlugins?: any[]; | |
@@ -144,6 +145,10 @@ export interface AppConfig { | |
*/ | |
watchPaths?: string | string[] | (() => Promise<string | string[]> | string | string[]); | |
future?: Partial<FutureConfig>; | |
+ /** | |
+ * A function for overriding the default esbuild configuration. | |
+ */ | |
+ esbuildOverride: (config: BuildOptions) => BuildOptions; | |
} | |
/** | |
* Fully resolved configuration object we use throughout Remix. | |
diff --git a/dist/config.js b/dist/config.js | |
index b2a4426c1b1d4def463fdf62d918b9f8f9b36405..72ba392c20cde5a36637e06f940d5961b7d5d153 100644 | |
--- a/dist/config.js | |
+++ b/dist/config.js | |
@@ -215,6 +215,7 @@ async function readConfig(remixRoot, serverMode = serverModes.ServerMode.Product | |
v2_meta: ((_appConfig$future9 = appConfig.future) === null || _appConfig$future9 === void 0 ? void 0 : _appConfig$future9.v2_meta) === true, | |
v2_routeConvention: ((_appConfig$future10 = appConfig.future) === null || _appConfig$future10 === void 0 ? void 0 : _appConfig$future10.v2_routeConvention) === true | |
}; | |
+ let esbuildOverride = appConfig.esbuildOverride || (config => config); | |
return { | |
appDirectory, | |
cacheDirectory, | |
@@ -243,7 +244,8 @@ async function readConfig(remixRoot, serverMode = serverModes.ServerMode.Product | |
mdx, | |
watchPaths, | |
tsconfigPath, | |
- future | |
+ future, | |
+ esbuildOverride | |
}; | |
} | |
function addTrailingSlash(path) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/no-var-requires */ | |
const { replace } = require("esbuild-plugin-replace"); | |
const { config } = require("dotenv"); | |
/** @type {import('@remix-run/dev').AppConfig} */ | |
module.exports = { | |
future: { | |
unstable_tailwind: true, | |
}, | |
devServerBroadcastDelay: 1000, | |
ignoredRouteFiles: ["**/.*"], | |
server: "./server.js", | |
serverBuildPath: "functions/[[path]].js", | |
serverConditions: ["worker"], | |
serverDependenciesToBundle: "all", | |
serverMainFields: ["browser", "module", "main"], | |
serverMinify: true, | |
serverModuleFormat: "esm", | |
serverPlatform: "neutral", | |
// appDirectory: "app", | |
// assetsBuildDirectory: "public/build", | |
// publicPath: "/build/", | |
esbuildOverride: (option) => { | |
config(); | |
const replaceValues = { | |
apiBaseUrl: process.env.API_BASE_URL, | |
}; | |
const missingValues = Object.entries(replaceValues).filter(([, value]) => !value); | |
if (missingValues.length > 0) { | |
throw new Error(`Missing values: ${missingValues.map(([key]) => key).join(", ")}`); | |
} | |
option.plugins = [ | |
...(option.plugins ?? []), | |
replace({ | |
values: { | |
__apiBaseUrl__: JSON.stringify(replaceValues.apiBaseUrl), | |
}, | |
include: /(\.jsx?|\.tsx?)$/, | |
}), | |
]; | |
option.legalComments = "inline"; | |
return option; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment