Skip to content

Commit

Permalink
Ignore buildOptions.baseUrl configuration for %BASE_URL% replacement …
Browse files Browse the repository at this point in the history
…in dev server (#957)
  • Loading branch information
FredKSchott authored Aug 28, 2020
1 parent de040f2 commit 5372aab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion snowpack/src/build/build-import-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ export function wrapImportMeta({
export function wrapHtmlResponse({
code,
hmr,
isDev,
config,
mode,
}: {
code: string;
hmr: boolean;
isDev: boolean;
config: SnowpackConfig;
mode: 'development' | 'production';
}) {
// replace %PUBLIC_URL% (along with surrounding slashes, if any)
code = code.replace(/\/?%PUBLIC_URL%\/?/g, config.buildOptions.baseUrl);
code = code.replace(/\/?%PUBLIC_URL%\/?/g, isDev ? '/' : config.buildOptions.baseUrl);

// replace %MODE%
code = code.replace(/%MODE%/g, mode);
Expand Down
1 change: 1 addition & 0 deletions snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class FileBuilder {
code = wrapHtmlResponse({
code,
hmr: false,
isDev: false,
config: this.config,
mode: 'production',
});
Expand Down
8 changes: 7 additions & 1 deletion snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,13 @@ export async function command(commandOptions: CommandOptions) {
) {
// transform special requests
if (isRoute) {
code = wrapHtmlResponse({code: code as string, hmr: isHmr, config, mode: 'development'});
code = wrapHtmlResponse({
code: code as string,
hmr: isHmr,
isDev: true,
config,
mode: 'development',
});
} else if (isProxyModule) {
responseFileExt = '.js';
} else if (isSourceMap && sourceMap) {
Expand Down

0 comments on commit 5372aab

Please sign in to comment.