Skip to content

Commit

Permalink
do not include public_url in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Aug 28, 2020
1 parent 843cf9e commit 5462a92
Show file tree
Hide file tree
Showing 3 changed files with 14 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
4 changes: 4 additions & 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 Expand Up @@ -292,6 +293,7 @@ export async function command(commandOptions: CommandOptions) {
async function installDependencies() {
const scannedFiles = Object.values(buildPipelineFiles)
.map((f) => Object.values(f.filesToResolve))
.filter(Boolean)
.reduce((flat, item) => flat.concat(item), []);
const installDest = path.join(buildDirectoryLoc, config.buildOptions.webModulesUrl);
const installResult = await installOptimizedDependencies(scannedFiles, installDest, {
Expand Down Expand Up @@ -477,4 +479,6 @@ export async function command(commandOptions: CommandOptions) {
watcher.on('add', (fileLoc) => onWatchEvent(fileLoc));
watcher.on('change', (fileLoc) => onWatchEvent(fileLoc));
watcher.on('unlink', (fileLoc) => onDeleteEvent(fileLoc));

return new Promise(() => {});
}
8 changes: 7 additions & 1 deletion snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,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 5462a92

Please sign in to comment.