@11ty/eleventy-dev-server
Advanced tools
Comparing version 1.0.0-canary.7 to 1.0.0-canary.8
@@ -48,2 +48,37 @@ class Util { | ||
} | ||
static isEleventyLinkNodeMatch(from, to) { | ||
// Issue #18 https://github.com/11ty/eleventy-dev-server/issues/18 | ||
// Don’t update a <link> if the _11ty searchParam is the only thing that’s different | ||
if(from.tagName !== "LINK" || to.tagName !== "LINK") { | ||
return false; | ||
} | ||
let oldWithoutHref = from.cloneNode(); | ||
let newWithoutHref = to.cloneNode(); | ||
oldWithoutHref.removeAttribute("href"); | ||
newWithoutHref.removeAttribute("href"); | ||
// if all other attributes besides href match | ||
if(!oldWithoutHref.isEqualNode(newWithoutHref)) { | ||
return false; | ||
} | ||
let oldUrl = new URL(from.href); | ||
let newUrl = new URL(to.href); | ||
// morphdom wants to force href="style.css?_11ty" => href="style.css" | ||
let isErasing = oldUrl.searchParams.has("_11ty") && !newUrl.searchParams.has("_11ty"); | ||
if(!isErasing) { | ||
// not a match if _11ty has a new value (not being erased) | ||
return false; | ||
} | ||
oldUrl.searchParams.set("_11ty", ""); | ||
newUrl.searchParams.set("_11ty", ""); | ||
// is a match if erasing and the rest of the href matches too | ||
return oldUrl.toString() === newUrl.toString(); | ||
} | ||
} | ||
@@ -80,3 +115,3 @@ | ||
morphed = true; | ||
morphdom(document.documentElement, template.content, { | ||
@@ -90,2 +125,7 @@ childrenOnly: true, | ||
} | ||
if(Util.isEleventyLinkNodeMatch(fromEl, toEl)) { | ||
return false; | ||
} | ||
return true; | ||
@@ -179,2 +219,2 @@ }, | ||
EleventyReload.init(); | ||
EleventyReload.init(); |
{ | ||
"name": "@11ty/eleventy-dev-server", | ||
"version": "1.0.0-canary.7", | ||
"version": "1.0.0-canary.8", | ||
"description": "A minimal, modern, generic, hot-reloading local web server to help web developers.", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -1,2 +0,2 @@ | ||
<p align="center"><img src="https://www.11ty.dev/img/logo-github.png" alt="eleventy Logo"></p> | ||
<p align="center"><img src="https://www.11ty.dev/img/logo-github.svg" width="200" height="200" alt="11ty Logo"></p> | ||
@@ -3,0 +3,0 @@ # eleventy-dev-server 🕚⚡️🎈🐀 |
@@ -171,15 +171,19 @@ const pkg = require("./package.json"); | ||
let filepath = TemplatePath.absolutePath( | ||
rootDir || __dirname, | ||
localpath | ||
); | ||
let filepath; | ||
let searchLocations = []; | ||
// fallback for file:../ installations | ||
if(rootDir && !fs.existsSync(filepath)) { | ||
filepath = TemplatePath.absolutePath( | ||
__dirname, | ||
localpath | ||
); | ||
if(rootDir) { | ||
searchLocations.push(TemplatePath.absolutePath(rootDir, localpath)); | ||
} | ||
// fallbacks for file:../ installations | ||
searchLocations.push(TemplatePath.absolutePath(__dirname, localpath)); | ||
searchLocations.push(TemplatePath.absolutePath(__dirname, "../../../", localpath)); | ||
for(let loc of searchLocations) { | ||
if(fs.existsSync(loc)) { | ||
filepath = loc; | ||
break; | ||
} | ||
} | ||
let contents = fs.readFileSync(filepath, { | ||
@@ -247,2 +251,18 @@ encoding: this.options.encoding, | ||
eleventyFolderMiddleware(req, res, next) { | ||
if(req.url === `/${this.options.folder}/reload-client.js`) { | ||
if(this.options.enabled) { | ||
res.setHeader("Content-Type", mime.getType("js")); | ||
return res.end(this._getFileContents("./client/reload-client.js")); | ||
} | ||
} else if(req.url === `/${this.options.folder}/morphdom.js`) { | ||
if(this.options.domdiff) { | ||
res.setHeader("Content-Type", mime.getType("js")); | ||
return res.end(this._getFileContents("./node_modules/morphdom/dist/morphdom-esm.js", path.resolve("."))); | ||
} | ||
} | ||
next(); | ||
} | ||
requestMiddleware(req, res) { | ||
@@ -269,14 +289,2 @@ // Known issue with `finalhandler` and HTTP/2: | ||
if(req.url === `/${this.options.folder}/reload-client.js`) { | ||
if(this.options.enabled) { | ||
res.setHeader("Content-Type", mime.getType("js")); | ||
return res.end(this._getFileContents("./client/reload-client.js")); | ||
} | ||
} else if(req.url === `/${this.options.folder}/morphdom.js`) { | ||
if(this.options.domdiff) { | ||
res.setHeader("Content-Type", mime.getType("js")); | ||
return res.end(this._getFileContents("./node_modules/morphdom/dist/morphdom-esm.js", path.resolve("."))); | ||
} | ||
} | ||
let match = this.mapUrlToFilePath(req.url); | ||
@@ -334,2 +342,4 @@ // console.log( req.url, match ); | ||
middlewares.push(this.eleventyFolderMiddleware); | ||
let bound = []; | ||
@@ -336,0 +346,0 @@ let next; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28018
711