From 6ce8a8d0a244545b1ad5f112771f2008d251eaec Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 14 Aug 2019 17:42:02 -0700 Subject: [PATCH] Fix the way the elm-pages module was being loaded. --- generator/src/develop.js | 2 +- index.js | 48 +++++++++++++++++++++++++++++++++++++++- lib/index.js | 47 --------------------------------------- package.json | 3 ++- 4 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 lib/index.js diff --git a/generator/src/develop.js b/generator/src/develop.js index 9e03a393..335ebd10 100644 --- a/generator/src/develop.js +++ b/generator/src/develop.js @@ -85,7 +85,7 @@ function webpackOptions(production, routes) { publicPath: "/" }, resolve: { - modules: [path.join(process.cwd(), "node_modules")], + modules: [path.resolve(process.cwd(), `./node_modules`)], extensions: [".js", ".elm", ".scss", ".png", ".html"] }, module: { diff --git a/index.js b/index.js index a420803c..54fde795 100644 --- a/index.js +++ b/index.js @@ -1 +1,47 @@ -console.log('Hello World!'); +module.exports = function pagesInit({ mainElmModule, imageAssets }) { + document.addEventListener("DOMContentLoaded", function() { + let app = mainElmModule.init({ + flags: { imageAssets } + }); + + app.ports.toJsPort.subscribe(headTags => { + if (navigator.userAgent.indexOf("Headless") >= 0) { + headTags.forEach(headTag => { + appendTag(headTag); + }); + } + + appendTag({ + name: "link", + attributes: [ + ["rel", "apple-touch-icon"], + ["sizes", "180x180"], + ["href", "/apple-touch-icon-180x180.png"] + ] + }); + appendTag({ + name: "link", + attributes: [ + ["rel", "apple-touch-icon"], + ["sizes", "1024x1024"], + ["href", "/apple-touch-icon-1024x1024.png"] + ] + }); + + appendTag({ + name: "link", + attributes: [["rel", "manifest"], ["href", "/manifest.webmanifest"]] + }); + + document.dispatchEvent(new Event("prerender-trigger")); + }); + }); + + function appendTag(tagDetails) { + const meta = document.createElement(tagDetails.name); + tagDetails.attributes.forEach(([name, value]) => { + meta.setAttribute(name, value); + }); + document.getElementsByTagName("head")[0].appendChild(meta); + } +}; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 54fde795..00000000 --- a/lib/index.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = function pagesInit({ mainElmModule, imageAssets }) { - document.addEventListener("DOMContentLoaded", function() { - let app = mainElmModule.init({ - flags: { imageAssets } - }); - - app.ports.toJsPort.subscribe(headTags => { - if (navigator.userAgent.indexOf("Headless") >= 0) { - headTags.forEach(headTag => { - appendTag(headTag); - }); - } - - appendTag({ - name: "link", - attributes: [ - ["rel", "apple-touch-icon"], - ["sizes", "180x180"], - ["href", "/apple-touch-icon-180x180.png"] - ] - }); - appendTag({ - name: "link", - attributes: [ - ["rel", "apple-touch-icon"], - ["sizes", "1024x1024"], - ["href", "/apple-touch-icon-1024x1024.png"] - ] - }); - - appendTag({ - name: "link", - attributes: [["rel", "manifest"], ["href", "/manifest.webmanifest"]] - }); - - document.dispatchEvent(new Event("prerender-trigger")); - }); - }); - - function appendTag(tagDetails) { - const meta = document.createElement(tagDetails.name); - tagDetails.attributes.forEach(([name, value]) => { - meta.setAttribute(name, value); - }); - document.getElementsByTagName("head")[0].appendChild(meta); - } -}; diff --git a/package.json b/package.json index a542ad00..61a931e2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "elm-pages", "version": "1.0.11", "description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.", - "main": "./lib/index.js", + "main": "index.js", "scripts": { "build": "cd generator && elm make src/Main.elm --output src/Main.js --optimize" }, @@ -47,6 +47,7 @@ }, "files": [ "dist/", + "index.js", "generator/bin/elm-pages", "generator/src/", "lib/manifest/index.js"