-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adding basic code splitting * feat: adding app-template, removing dep, adding eslintignore * feat: adding loading and spinner components, fix test * fix: dependencies removed * fix: adjust chunk filenames * feat: combine chunks based on page routes * feat: allow splitchunkplugin from config * fix: condense optimization config * fix: remove formatting issues * fix: chunks arr and remove loading component * fix: remove chunk optimization * fix: add min content height, stop footer flash * remove forced formatting Co-authored-by: Owen Buckley <[email protected]>
- Loading branch information
1 parent
da25c20
commit 73547bd
Showing
7 changed files
with
151 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { html, css, LitElement } from 'lit-element'; | ||
import { connectRouter } from 'lit-redux-router'; | ||
import { applyMiddleware, createStore, compose as origCompose, combineReducers } from 'redux'; | ||
import { lazyReducerEnhancer } from 'pwa-helpers/lazy-reducer-enhancer.js'; | ||
import thunk from 'redux-thunk'; | ||
import client from '@greenwood/cli/data/client'; | ||
import ConfigQuery from '@greenwood/cli/data/queries/config'; | ||
import GraphQuery from '@greenwood/cli/data/queries/graph'; | ||
import '../components/header/header'; | ||
import '../components/footer/footer'; | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
const compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || origCompose; | ||
|
||
// eslint-disable-next-line | ||
const store = createStore( | ||
(state, action) => state, // eslint-disable-line | ||
compose(lazyReducerEnhancer(combineReducers), applyMiddleware(thunk))); | ||
|
||
import '../index/index'; | ||
|
||
connectRouter(store); | ||
|
||
class AppComponent extends LitElement { | ||
|
||
static get styles() { | ||
return css` | ||
.content-outlet { | ||
min-height: 100vh | ||
}`; | ||
} | ||
|
||
async connectedCallback() { | ||
super.connectedCallback(); | ||
const route = window.location.pathname; | ||
const response = await Promise.all([ | ||
await client.query({ | ||
query: ConfigQuery | ||
}), | ||
await client.query({ | ||
query: GraphQuery | ||
}) | ||
]); | ||
const { config } = response[0].data; | ||
const currentPage = response[1].data.graph.filter((page) => { | ||
return route === page.link; | ||
})[0]; | ||
|
||
const currentPageTitleSuffix = !currentPage || currentPage.link === '/' | ||
? '' | ||
: ` - ${currentPage.title}`; | ||
const fullTitle = `${config.title}${currentPageTitleSuffix}`; | ||
|
||
this.setDocumentTitle(fullTitle); | ||
this.setMeta(config.meta, currentPage); | ||
} | ||
|
||
setDocumentTitle(title = '') { | ||
const head = document.head; | ||
const titleElement = head.getElementsByTagName('title')[0]; | ||
|
||
titleElement.innerHTML = title; | ||
} | ||
|
||
setMeta(meta = [], currentPage = {}) { | ||
let header = document.head; | ||
|
||
meta.forEach(metaItem => { | ||
const metaType = metaItem.rel // type of meta | ||
? 'rel' | ||
: metaItem.name | ||
? 'name' | ||
: 'property'; | ||
const metaTypeValue = metaItem[metaType]; // value of the meta | ||
let meta = document.createElement('meta'); | ||
|
||
if (metaType === 'rel') { | ||
// change to a <link> tag instead | ||
meta = document.createElement('link'); | ||
|
||
meta.setAttribute('rel', metaTypeValue); | ||
meta.setAttribute('href', metaItem.href); | ||
} else { | ||
const metaContent = metaItem.property === 'og:url' | ||
? `${metaItem.content}${currentPage.link}` | ||
: metaItem.content; | ||
|
||
meta.setAttribute(metaType, metaItem[metaType]); | ||
meta.setAttribute('content', metaContent); | ||
} | ||
|
||
const oldmeta = header.querySelector(`[${metaType}="${metaTypeValue}"]`); | ||
|
||
// rehydration | ||
if (oldmeta) { | ||
header.replaceChild(meta, oldmeta); | ||
} else { | ||
header.appendChild(meta); | ||
} | ||
}); | ||
} | ||
|
||
render() { | ||
return html` | ||
<div class='wrapper'> | ||
<eve-header></eve-header> | ||
<div class="content-outlet"> | ||
MYROUTES | ||
</div> | ||
<lit-route><h1>404 Not found</h1></lit-route> | ||
<eve-footer></eve-footer> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('eve-app', AppComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters