Fix the way the elm-pages module was being loaded.

This commit is contained in:
Dillon Kearns 2019-08-14 17:42:02 -07:00
parent f8168edd69
commit 6ce8a8d0a2
4 changed files with 50 additions and 50 deletions

View File

@ -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: {

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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"