Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/resource/plugin-active-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ContentAsDataResource {
async shouldIntercept(url, request, response) {
const { activeContent } = this.compilation.config;

return response.headers.get("Content-Type")?.indexOf(this.contentType[0]) >= 0 && activeContent;
return activeContent && response.headers.get("Content-Type")?.indexOf(this.contentType[0]) >= 0;
}

async intercept(url, request, response) {
Expand Down Expand Up @@ -138,7 +138,7 @@ class ContentAsDataResource {
async shouldOptimize(url, response) {
const { activeContent } = this.compilation.config;

return response.headers.get("Content-Type").indexOf(this.contentType[0]) >= 0 && activeContent;
return activeContent && response.headers.get("Content-Type")?.indexOf(this.contentType[0]) >= 0;
}

async optimize(url, response) {
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/plugins/resource/plugin-node-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ class NodeModulesResource {
}

async shouldServe(url) {
const { href, protocol } = url;
const { href, protocol, pathname } = url;

return protocol === "file:" && (await checkResourceExists(new URL(href)));
return (
protocol === "file:" &&
pathname.indexOf("/node_modules/") >= 0 &&
(await checkResourceExists(new URL(href)))
);
}

async serve(url) {
const body = await fs.readFile(url, "utf-8");

// most likely a JavaScript file, but perhaps we should further refine based on extension?
return new Response(body, {
headers: new Headers({
"Content-Type": this.contentType,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-standard-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { parse } from "node-html-parser";
class StandardHtmlResource {
constructor(compilation) {
this.compilation = compilation;
this.extensions = [".html"];
this.extensions = ["html"];
this.contentType = "text/html";
}

Expand Down
Loading