Skip to content

Commit d5309ea

Browse files
fix(remix-dev/vite): warn on source maps in build (#8222)
1 parent b07e20d commit d5309ea

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

packages/remix-dev/vite/plugin.ts

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ const getRouteModuleExports = async (
279279
const showUnstableWarning = () => {
280280
console.warn(
281281
colors.yellow(
282-
"\n ⚠️ Remix support for Vite is unstable\n and not recommended for production\n"
282+
colors.bold(
283+
"\n ⚠️ Remix support for Vite is unstable and\n not yet recommended for production\n"
284+
)
283285
)
284286
);
285287
};
@@ -295,7 +297,7 @@ export type RemixVitePlugin = (
295297
export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
296298
let viteCommand: Vite.ResolvedConfig["command"];
297299
let viteUserConfig: Vite.UserConfig;
298-
let resolvedViteConfig: Vite.ResolvedConfig | undefined;
300+
let viteConfig: Vite.ResolvedConfig | undefined;
299301

300302
let isViteV4 = getViteMajorVersion() === 4;
301303

@@ -640,10 +642,10 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
640642
}),
641643
};
642644
},
643-
async configResolved(viteConfig) {
645+
async configResolved(resolvedViteConfig) {
644646
await initEsModuleLexer;
645647

646-
resolvedViteConfig = viteConfig;
648+
viteConfig = resolvedViteConfig;
647649

648650
ssrBuildContext =
649651
viteConfig.build.ssr && viteCommand === "build"
@@ -719,9 +721,38 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
719721
}
720722
},
721723
buildStart() {
722-
if (viteCommand === "build") {
724+
invariant(viteConfig);
725+
726+
if (
727+
viteCommand === "build" &&
728+
// Only show warning on initial client build
729+
!viteConfig.build.ssr
730+
) {
723731
showUnstableWarning();
724732
}
733+
734+
if (
735+
viteCommand === "build" &&
736+
viteConfig.mode === "production" &&
737+
!viteConfig.build.ssr &&
738+
viteConfig.build.sourcemap
739+
) {
740+
viteConfig.logger.warn(
741+
colors.yellow(
742+
colors.bold(" ⚠️ Source maps are enabled in production\n") +
743+
[
744+
"This makes your server code publicly",
745+
"visible in the browser. This is highly",
746+
"discouraged! If you insist, ensure that",
747+
"you are using environment variables for",
748+
"secrets and not hard-coding them in",
749+
"your source code.\n",
750+
]
751+
.map((line) => " " + line)
752+
.join("\n")
753+
)
754+
);
755+
}
725756
},
726757
configureServer(viteDevServer) {
727758
viteDevServer.httpServer?.on("listening", () => {
@@ -814,15 +845,8 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
814845
return;
815846
}
816847

817-
invariant(
818-
cachedPluginConfig,
819-
"Expected plugin config to be cached when writeBundle hook is called"
820-
);
821-
822-
invariant(
823-
resolvedViteConfig,
824-
"Expected resolvedViteConfig to exist when writeBundle hook is called"
825-
);
848+
invariant(cachedPluginConfig);
849+
invariant(viteConfig);
826850

827851
let { assetsBuildDirectory, serverBuildPath, rootDirectory } =
828852
cachedPluginConfig;
@@ -872,10 +896,8 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
872896
)
873897
);
874898

875-
let logger = resolvedViteConfig.logger;
876-
877899
if (movedAssetPaths.length) {
878-
logger.info(
900+
viteConfig.logger.info(
879901
[
880902
"",
881903
`${colors.green("✓")} ${movedAssetPaths.length} asset${

0 commit comments

Comments
 (0)