Skip to content

Commit

Permalink
fix: proxy file when dev (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonBall authored Aug 27, 2020
1 parent a2e16de commit 75b23c3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,17 @@ export async function command(commandOptions: CommandOptions) {
* return a JS representation of that CSS. This is handled in the wrap step.
*/
async function wrapResponse(
code: string,
code: string | Buffer,
{
hasCssResource,
sourceMap,
sourceMappingURL,
}: {hasCssResource: boolean; sourceMap?: string; sourceMappingURL: string},
) {
// transform special requests
const stringCode = code as string;
if (isRoute) {
code = wrapHtmlResponse({code: code, hmr: isHmr, config, mode: 'development'});
code = wrapHtmlResponse({code: stringCode, hmr: isHmr, config, mode: 'development'});
} else if (isProxyModule) {
responseFileExt = '.js';
} else if (isSourceMap && sourceMap) {
Expand All @@ -509,14 +510,14 @@ export async function command(commandOptions: CommandOptions) {
// transform other files
switch (responseFileExt) {
case '.css': {
if (sourceMap) code = cssSourceMappingURL(code, sourceMappingURL);
if (sourceMap) code = cssSourceMappingURL(stringCode, sourceMappingURL);
break;
}
case '.js': {
if (isProxyModule) {
code = await wrapImportProxy({url: reqPath, code, hmr: isHmr, config});
} else {
code = wrapImportMeta({code, env: true, hmr: isHmr, config});
code = wrapImportMeta({code: stringCode, env: true, hmr: isHmr, config});
}

if (hasCssResource)
Expand Down Expand Up @@ -626,7 +627,7 @@ If Snowpack is having trouble detecting the import, add ${colors.bold(
}

const {code, map} = output[requestedFileExt];
if (typeof code !== 'string') return code; // return binary files as-is
if (typeof code !== 'string' && !isProxyModule) return code; // return binary files as-is
let finalResponse = code;

// Resolve imports.
Expand All @@ -635,7 +636,11 @@ If Snowpack is having trouble detecting the import, add ${colors.bold(
requestedFileExt === '.html' ||
requestedFileExt === '.css'
) {
finalResponse = await resolveResponseImports(fileLoc, requestedFileExt, finalResponse);
finalResponse = await resolveResponseImports(
fileLoc,
requestedFileExt,
finalResponse as string,
);
}

// Wrap the response.
Expand Down

1 comment on commit 75b23c3

@vercel
Copy link

@vercel vercel bot commented on 75b23c3 Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.