Skip to content

Commit

Permalink
Fix loading index.html in dev server when packager/optimizer changes …
Browse files Browse the repository at this point in the history
…bundle type
  • Loading branch information
devongovett committed Jan 5, 2022
1 parent 5a80fbe commit cc8ba78
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/core/core/src/public/Bundle.js
Expand Up @@ -314,6 +314,10 @@ export class PackagedBundle extends NamedBundle implements IPackagedBundle {
);
}

get type(): string {
return nullthrows(this.#bundleInfo).type;
}

get stats(): Stats {
return nullthrows(this.#bundleInfo).stats;
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/requests/WriteBundleRequest.js
Expand Up @@ -181,6 +181,7 @@ async function run({input, options, api}: RunInput) {

let res = {
filePath,
type: info.type,
stats: {
size,
time: info.time ?? 0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/requests/WriteBundlesRequest.js
Expand Up @@ -71,6 +71,7 @@ async function run({input, api, farm, options}: RunInput) {
let name = nullthrows(bundle.name).replace(bundle.hashReference, hash);
res.set(bundle.id, {
filePath: joinProjectPath(bundle.target.distDir, name),
type: bundle.type, // FIXME: this is wrong if the packager changes the type...
stats: {
time: 0,
size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/types.js
Expand Up @@ -500,6 +500,7 @@ export type BundleGroupNode = {|

export type PackagedBundleInfo = {|
filePath: ProjectPath,
type: string,
stats: Stats,
|};

Expand Down
23 changes: 13 additions & 10 deletions packages/reporters/dev-server/src/Server.js
Expand Up @@ -161,16 +161,19 @@ export default class Server {
sendIndex(req: Request, res: Response) {
if (this.bundleGraph) {
// If the main asset is an HTML file, serve it
let htmlBundleFilePaths = [];
this.bundleGraph.traverseBundles(bundle => {
if (bundle.type === 'html' && bundle.bundleBehavior !== 'inline') {
htmlBundleFilePaths.push(bundle.filePath);
}
});

htmlBundleFilePaths = htmlBundleFilePaths.map(p => {
return `/${relativePath(this.options.distDir, p, false)}`;
});
let htmlBundleFilePaths = this.bundleGraph
.getBundles()
.filter(
bundle =>
bundle.type === 'html' && bundle.bundleBehavior !== 'inline',
)
.map(bundle => {
return `/${relativePath(
this.options.distDir,
bundle.filePath,
false,
)}`;
});

let indexFilePath = null;
if (htmlBundleFilePaths.length === 1) {
Expand Down

0 comments on commit cc8ba78

Please sign in to comment.