Run prettier.

This commit is contained in:
Dillon Kearns 2020-04-13 15:12:16 -07:00
parent fb9d3e5ed6
commit b614a4cd26
2 changed files with 21 additions and 21 deletions

View File

@ -44,14 +44,14 @@ function start({ routes, debug, customPort, manifestConfig, routesWithRequests,
log: console.log, path: '/__webpack_hmr' log: console.log, path: '/__webpack_hmr'
})) }))
app.use("*", function(req, res, next) { app.use("*", function (req, res, next) {
// don't know why this works, but it does // don't know why this works, but it does
// see: https://github.com/jantimon/html-webpack-plugin/issues/145#issuecomment-170554832 // see: https://github.com/jantimon/html-webpack-plugin/issues/145#issuecomment-170554832
const filename = path.join(compiler.outputPath, "index.html"); const filename = path.join(compiler.outputPath, "index.html");
const route = req.originalUrl.replace(/(\w)\/$/, "$1").replace(/^\//, ""); const route = req.originalUrl.replace(/(\w)\/$/, "$1").replace(/^\//, "");
const isPage = routes.includes(route); const isPage = routes.includes(route);
compiler.outputFileSystem.readFile(filename, function(err, result) { compiler.outputFileSystem.readFile(filename, function (err, result) {
const contents = isPage const contents = isPage
? replaceBaseAndLinks(result.toString(), route) ? replaceBaseAndLinks(result.toString(), route)
: result : result
@ -249,7 +249,7 @@ function webpackOptions(
// process.cwd prefixed node_modules above). // process.cwd prefixed node_modules above).
path.resolve(path.dirname(require.resolve('webpack')), '../../'), path.resolve(path.dirname(require.resolve('webpack')), '../../'),
], ],
extensions: [".js", ".elm", ".scss", ".png", ".html"] extensions: [".js", ".elm", ".scss", ".png", ".html"]
}, },
module: { module: {
@ -356,7 +356,7 @@ function webpackOptions(
entry: [ entry: [
require.resolve("webpack-hot-middleware/client"), require.resolve("webpack-hot-middleware/client"),
"./index.js", "./index.js",
], ],
plugins: [ plugins: [
new webpack.NamedModulesPlugin(), new webpack.NamedModulesPlugin(),
// Prevents compilation errors causing the hot loader to lose state // Prevents compilation errors causing the hot loader to lose state
@ -395,10 +395,10 @@ function pathToRoot(cleanedRoute) {
return cleanedRoute === "" return cleanedRoute === ""
? cleanedRoute ? cleanedRoute
: cleanedRoute : cleanedRoute
.split("/") .split("/")
.map(_ => "..") .map(_ => "..")
.join("/") .join("/")
.replace(/\.$/, "./") .replace(/\.$/, "./")
} }

View File

@ -11,9 +11,9 @@ module.exports = function pagesInit(
prefetchedPages = [window.location.pathname]; prefetchedPages = [window.location.pathname];
initialLocationHash = document.location.hash.replace(/^#/, ""); initialLocationHash = document.location.hash.replace(/^#/, "");
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
document.addEventListener("DOMContentLoaded", _ => { document.addEventListener("DOMContentLoaded", _ => {
new MutationObserver(function() { new MutationObserver(function () {
elmViewRendered = true; elmViewRendered = true;
if (headTagsAdded) { if (headTagsAdded) {
document.dispatchEvent(new Event("prerender-trigger")); document.dispatchEvent(new Event("prerender-trigger"));
@ -32,7 +32,7 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
const isPrerendering = navigator.userAgent.indexOf("Headless") >= 0 const isPrerendering = navigator.userAgent.indexOf("Headless") >= 0
const path = window.location.pathname.replace(/(\w)$/, "$1/") const path = window.location.pathname.replace(/(\w)$/, "$1/")
return httpGet(`${window.location.origin}${path}content.json`).then(function(/** @type JSON */ contentJson) { return httpGet(`${window.location.origin}${path}content.json`).then(function (/** @type JSON */ contentJson) {
const app = mainElmModule.init({ const app = mainElmModule.init({
flags: { flags: {
@ -62,10 +62,10 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
fromElm.head.forEach(headTag => { fromElm.head.forEach(headTag => {
appendTag(headTag); appendTag(headTag);
}); });
headTagsAdded = true; headTagsAdded = true;
if (elmViewRendered) { if (elmViewRendered) {
document.dispatchEvent(new Event("prerender-trigger")); document.dispatchEvent(new Event("prerender-trigger"));
} }
} else { } else {
setupLinkPrefetching(); setupLinkPrefetching();
} }
@ -73,7 +73,7 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
if (module.hot) { if (module.hot) {
module.hot.addStatusHandler(function(status) { module.hot.addStatusHandler(function (status) {
if (status === 'idle') { if (status === 'idle') {
console.log('Reloaded!!!!!!!!!!', status) console.log('Reloaded!!!!!!!!!!', status)
app.ports.fromJsPort.send({}); app.ports.fromJsPort.send({});
@ -142,7 +142,7 @@ function setupLinkPrefetchingHelp(
const links = document.querySelectorAll("a"); const links = document.querySelectorAll("a");
links.forEach(link => { links.forEach(link => {
// console.log(link.pathname); // console.log(link.pathname);
link.addEventListener("mouseenter", function(event) { link.addEventListener("mouseenter", function (event) {
if ( if (
event && event &&
event.target && event.target &&
@ -186,11 +186,11 @@ function appendTag(/** @type {HeadTag} */ tagDetails) {
} }
function httpGet(/** @type string */ theUrl) { function httpGet(/** @type string */ theUrl) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
const xmlHttp = new XMLHttpRequest(); const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
resolve(JSON.parse(xmlHttp.responseText)); resolve(JSON.parse(xmlHttp.responseText));
} }
xmlHttp.onerror = reject; xmlHttp.onerror = reject;
xmlHttp.open("GET", theUrl, true); // true for asynchronous xmlHttp.open("GET", theUrl, true); // true for asynchronous