Skip to content

Commit

Permalink
resolve urls first, then proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Oct 30, 2020
1 parent 25eb4d1 commit aae7908
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
21 changes: 9 additions & 12 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
}

// When dealing with an absolute import path, we need to honor the baseUrl
if (isAbsoluteUrlPath) {
// proxy modules may attach code to the root HTML (like style) so don't resolve
if (isAbsoluteUrlPath && !isProxyModule) {
resolvedImportUrl = relativeURL(path.posix.dirname(reqPath), resolvedImportUrl);
}
// Make sure that a relative URL always starts with "./"
Expand Down Expand Up @@ -886,18 +887,8 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
if (!output[requestedFileExt] || !Object.keys(output)) {
return null;
}

const {code, map} = output[requestedFileExt];
let finalResponse = code;

// Wrap the response.
const hasAttachedCss = requestedFileExt === '.js' && !!output['.css'];
finalResponse = await wrapResponse(finalResponse, {
hasCssResource: hasAttachedCss,
sourceMap: map,
sourceMappingURL: path.basename(requestedFile.base) + '.map',
});

// Resolve imports.
if (
requestedFileExt === '.js' ||
Expand All @@ -910,7 +901,13 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
finalResponse as string,
);
}

// Wrap the response.
const hasAttachedCss = requestedFileExt === '.js' && !!output['.css'];
finalResponse = await wrapResponse(finalResponse, {
hasCssResource: hasAttachedCss,
sourceMap: map,
sourceMappingURL: path.basename(requestedFile.base) + '.map',
});
// Return the finalized response.
return finalResponse;
}
Expand Down
3 changes: 3 additions & 0 deletions test/build/package-bootstrap/__snapshots__
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`snowpack build package-bootstrap: allFiles 1`] = `
Array [
"__snowpack__/env.js",
"_dist_/index.js",
"_dist_/style.css",
"web_modules/bootstrap/dist/css/bootstrap.min.css",
"web_modules/bootstrap/dist/css/bootstrap.min.css.proxy.js",
"web_modules/import-map.json",
Expand All @@ -17,6 +18,8 @@ exports[`snowpack build package-bootstrap: build/_dist_/index.js 1`] = `
console.log('CSS added to page!');"
`;

exports[`snowpack build package-bootstrap: build/_dist_/style.css 1`] = `"@import \\"../web_modules/bootstrap/dist/css/bootstrap.min.css\\";"`;

exports[`snowpack build package-bootstrap: build/web_modules/bootstrap/dist/css/bootstrap.min.css 1`] = `
"/*!
* Bootstrap v4.5.2 (https://getbootstrap.com/)
Expand Down

1 comment on commit aae7908

@vercel
Copy link

@vercel vercel bot commented on aae7908 Oct 30, 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.