eddev 0.2.27 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/components/ImageWell.d.ts +1 -0
- package/build/get-webpack-config.js +1 -0
- package/build/serverless/create-next-app.js +5 -5
- package/cli/display/components/BundleDisplay.d.ts +1 -0
- package/cli/display/components/CodegenDisplay.d.ts +1 -0
- package/cli/display/components/DevCLIDisplay.d.ts +1 -0
- package/cli/display/components/ServerlessDisplay.d.ts +1 -0
- package/cli/display/components/StatusIcon.d.ts +1 -0
- package/components/AdminBar.d.ts +1 -0
- package/dev-ui/components/BreakpointColumnHeader.d.ts +1 -0
- package/dev-ui/components/BreakpointIndicator.d.ts +1 -0
- package/dev-ui/components/DevUI.d.ts +1 -0
- package/dev-ui/components/ResponsiveLerpControl.d.ts +1 -0
- package/dev-ui/components/ResponsiveScaleEditor.d.ts +1 -0
- package/dev-ui/components/atoms/NumberField.d.ts +1 -0
- package/dev-ui/components/panels/PageDataDebugger.d.ts +1 -0
- package/dev-ui/components/panels/SpacingEditor.d.ts +1 -0
- package/dev-ui/components/panels/TypographyEditor.d.ts +1 -0
- package/dev-ui/icons.d.ts +1 -0
- package/dev-ui/loader.d.ts +1 -0
- package/dev-ui/theme.d.ts +3 -2
- package/dynamic/dynamic-component.d.ts +1 -0
- package/entry/Root.d.ts +1 -0
- package/gravityforms/useGravityForm.js +13 -3
- package/package.json +4 -3
- package/serverless-template/tsconfig.json +1 -0
- package/style/createStitches.d.ts +3 -2
- package/docs_old/README.md +0 -33
- package/docs_old/babel.config.js +0 -3
- package/docs_old/blog/2019-05-28-first-blog-post.md +0 -12
- package/docs_old/blog/2019-05-29-long-blog-post.md +0 -44
- package/docs_old/blog/2021-08-01-mdx-blog-post.mdx +0 -20
- package/docs_old/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg +0 -0
- package/docs_old/blog/2021-08-26-welcome/index.md +0 -25
- package/docs_old/blog/authors.yml +0 -17
- package/docs_old/docs/graphql/1.graphql-overview.md +0 -62
- package/docs_old/docs/graphql/2.query-hooks.md +0 -238
- package/docs_old/docs/graphql/3.extending-wpgraphql.md +0 -3
- package/docs_old/docs/graphql/_category_.json +0 -4
- package/docs_old/docs/graphql/img/graphql-ide.png +0 -0
- package/docs_old/docs/graphql/img/infinite-example.gif +0 -0
- package/docs_old/docs/graphql/img/mutation-example.gif +0 -0
- package/docs_old/docs/gutenberg/1.overview.md +0 -25
- package/docs_old/docs/gutenberg/2.block-definition.md +0 -37
- package/docs_old/docs/gutenberg/3.block-acf.md +0 -13
- package/docs_old/docs/gutenberg/4.block-graphql.md +0 -63
- package/docs_old/docs/gutenberg/5.inline-editing.md +0 -33
- package/docs_old/docs/gutenberg/6.nested-blocks.md +0 -80
- package/docs_old/docs/gutenberg/7.restricting-to-post-types.md +0 -38
- package/docs_old/docs/gutenberg/8.restricting-to-page-templates.md +0 -26
- package/docs_old/docs/gutenberg/9.dynamic-blocks.md +0 -21
- package/docs_old/docs/gutenberg/_category_.json +0 -4
- package/docs_old/docs/gutenberg/img/create-acf-fields-for-block.png +0 -0
- package/docs_old/docs/gutenberg/img/example-acf-single-project-tile.png +0 -0
- package/docs_old/docs/how-to/1.new-site.md +0 -36
- package/docs_old/docs/how-to/2.deployment.md +0 -31
- package/docs_old/docs/how-to/3.menus.md +0 -72
- package/docs_old/docs/how-to/4.options-pages.md +0 -41
- package/docs_old/docs/how-to/5.bundle-size.md +0 -177
- package/docs_old/docs/how-to/6.favicons.md +0 -82
- package/docs_old/docs/how-to/_category_.json +0 -4
- package/docs_old/docs/how-to/img/bundle-analysis-after.png +0 -0
- package/docs_old/docs/how-to/img/bundle-analysis-before.png +0 -0
- package/docs_old/docs/how-to/img/bundle-webpack-after.png +0 -0
- package/docs_old/docs/how-to/img/bundle-webpack-before.png +0 -0
- package/docs_old/docs/how-to/img/favicon-codebase.png +0 -0
- package/docs_old/docs/how-to/img/favicon-figma-export.png +0 -0
- package/docs_old/docs/how-to/img/favicon-figma.png +0 -0
- package/docs_old/docs/intro.md +0 -7
- package/docs_old/docs/known-issues.md +0 -8
- package/docs_old/docs/serverless/1.overview.md +0 -1
- package/docs_old/docs/serverless/2.config.md +0 -1
- package/docs_old/docs/serverless/3.wordpress-vercel.md +0 -8
- package/docs_old/docs/serverless/4.apis.md +0 -1
- package/docs_old/docs/serverless/5.rpc.md +0 -1
- package/docs_old/docs/serverless/_category_.json +0 -4
- package/docs_old/docs/stack/1-WordPress.md +0 -18
- package/docs_old/docs/stack/2-Flywheel.md +0 -15
- package/docs_old/docs/stack/3-React.md +0 -12
- package/docs_old/docs/stack/4-TypeScript.md +0 -13
- package/docs_old/docs/stack/5-WPGraphQL.md +0 -21
- package/docs_old/docs/stack/6-eddev.md +0 -9
- package/docs_old/docs/stack/_category_.json +0 -4
- package/docs_old/docs/tooling/1.scripts.md +0 -25
- package/docs_old/docs/tooling/2.aliases.md +0 -13
- package/docs_old/docs/tooling/3.defines.md +0 -13
- package/docs_old/docs/tooling/4.config-file.md +0 -14
- package/docs_old/docs/tooling/_category_.json +0 -4
- package/docs_old/docs/views/1.overview.md +0 -31
- package/docs_old/docs/views/2.queries.md +0 -18
- package/docs_old/docs/views/3.content-blocks.md +0 -36
- package/docs_old/docs/views/4.app-view.md +0 -35
- package/docs_old/docs/views/5.page-templates.md +0 -20
- package/docs_old/docs/views/_category_.json +0 -4
- package/docs_old/docusaurus.config.js +0 -119
- package/docs_old/package.json +0 -40
- package/docs_old/sidebars.js +0 -26
- package/docs_old/src/components/HomepageFeatures.js +0 -64
- package/docs_old/src/components/HomepageFeatures.module.css +0 -11
- package/docs_old/src/css/custom.css +0 -28
- package/docs_old/src/pages/index.js +0 -36
- package/docs_old/src/pages/index.module.css +0 -23
- package/docs_old/src/pages/markdown-page.md +0 -7
- package/docs_old/static/.nojekyll +0 -0
- package/docs_old/static/img/docusaurus.png +0 -0
- package/docs_old/static/img/favicon.ico +0 -0
- package/docs_old/static/img/logo-black.svg +0 -4
- package/docs_old/static/img/logo-white.svg +0 -4
- package/docs_old/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/docs_old/static/img/tutorial/localeDropdown.png +0 -0
- package/docs_old/static/img/undraw_docusaurus_mountain.svg +0 -170
- package/docs_old/static/img/undraw_docusaurus_react.svg +0 -169
- package/docs_old/static/img/undraw_docusaurus_tree.svg +0 -1
- package/docs_old/yarn.lock +0 -8814
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Deployment
|
|
2
|
-
|
|
3
|
-
There are some prerequisites for setting up deployment.
|
|
4
|
-
|
|
5
|
-
1. You've got an SSH key set up on your computer, which has been added to both Github and Flywheel. You only need to do this once for your computer.
|
|
6
|
-
2. You've set up the site on Flywheel already, and completed an initial push using Local Sync.
|
|
7
|
-
|
|
8
|
-
Assuming the above prerequisites are met, setting up deployment is easy!
|
|
9
|
-
|
|
10
|
-
1. Grab the Flywheel SSH user for your site.
|
|
11
|
-
1. On the [Flywheel Dashboard](https://app.getflywheel.com/sites), locate the relevant site.
|
|
12
|
-
2. Click the 'Advanced' tab.
|
|
13
|
-
3. Copy the user component from the 'Connect via SSH' section.
|
|
14
|
-
(For example, if the connection string is `ssh team+ed-digital+the-yards@ssh.getflywheel.com`), the value is `team+ed-digital+the-yards`.
|
|
15
|
-
2. Grab your private key.
|
|
16
|
-
1. Assuming you're using your default private key, and that it's in the correct format already, you can just run `cat ~/.ssh/id_rsa | pbcopy` in your terminal to copy this directly to your clipboard.
|
|
17
|
-
3. Paste the secrets into the Github repo's 'Secrets' panel.
|
|
18
|
-
1. Open the repo on Github, and click Settings -> Secrets.
|
|
19
|
-
2. Add a new secret called `SSH_USER` and paste in the value from step 1. Save it!
|
|
20
|
-
3. Add a new secret called `PRIVATE_KEY` and paste in the value from step 2. Save it!
|
|
21
|
-
4. Finally, rename `.github/workflows/main.yaml.disabled` to `.github/workflows/main.yaml` and commit/push the results.
|
|
22
|
-
```
|
|
23
|
-
mv .github/workflows/main.yaml.disabled .github/workflows/main.yaml
|
|
24
|
-
git commit -am "Enable Github Action deployment"
|
|
25
|
-
git push
|
|
26
|
-
```
|
|
27
|
-
5. Monitor the 'Actions' tab on your Github repo page to ensure that the first deployment succeeded.
|
|
28
|
-
|
|
29
|
-
:::tip warning
|
|
30
|
-
Your first deploy might fail to run at the 'Install Dependencies' step. Try running 'Re-run all jobs'.
|
|
31
|
-
:::
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Menus
|
|
2
|
-
|
|
3
|
-
For simplicities sake, all menus are pre-loaded in the starter theme's `views/_app.graphql`. It looks something like this:
|
|
4
|
-
|
|
5
|
-
```graphql title="views/_app.graphql"
|
|
6
|
-
query CommonData {
|
|
7
|
-
menus {
|
|
8
|
-
nodes {
|
|
9
|
-
menuItems {
|
|
10
|
-
nodes {
|
|
11
|
-
...MenuItemFields
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
locations
|
|
15
|
-
slug
|
|
16
|
-
name
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
fragment MenuItemFields on MenuItem {
|
|
22
|
-
label
|
|
23
|
-
title
|
|
24
|
-
target
|
|
25
|
-
url
|
|
26
|
-
cssClasses
|
|
27
|
-
childItems {
|
|
28
|
-
nodes {
|
|
29
|
-
label
|
|
30
|
-
title
|
|
31
|
-
target
|
|
32
|
-
url
|
|
33
|
-
cssClasses
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The fragment is used there so that it's easy to grab TypeScript types for the menu data structure.
|
|
40
|
-
|
|
41
|
-
There's also a `backend/menus.php` file, which has a call to `register_nav_menus` function call, which sets up 'menu locations'. If you need more than just one menu, you can add them there.
|
|
42
|
-
|
|
43
|
-
```php
|
|
44
|
-
register_nav_menus([
|
|
45
|
-
'main' => 'Main Menu',
|
|
46
|
-
'footer' => 'Footer Menu'
|
|
47
|
-
]);
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
The starter theme also comes with a `components/atoms/Menu.tsx` component. It's included as a component which you can tailor to your needs.
|
|
51
|
-
|
|
52
|
-
To use the menu component, you'll need to specify the menu location which you defined in PHP. Assuming you've got `yarn dev` running, the menu locations will auto-complete with TypeScript.
|
|
53
|
-
|
|
54
|
-
```tsx
|
|
55
|
-
<Menu location="Main">
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
It's recommended that if you need to stylise or customise the Menu, that you kinda keep that file nice and generic, and create a new component which uses the `Menu` component as a base. (Or alternatively, you can always copy/paste the `Menu` code into your new component.)
|
|
59
|
-
|
|
60
|
-
```tsx title="components/atoms/MyCoolMenu.tsx
|
|
61
|
-
import { Menu } from "@components/atoms/Menus"
|
|
62
|
-
|
|
63
|
-
export const MyCoolMenu = styled(Menu, {
|
|
64
|
-
display: "flex",
|
|
65
|
-
li: {
|
|
66
|
-
marginLeft: "20px",
|
|
67
|
-
a: {
|
|
68
|
-
fontFamily: '"Comic Sans"',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
```
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Options Pages
|
|
2
|
-
|
|
3
|
-
You can create an 'Options Page' on the WordPress sidebar to create a space for global ACF fields.
|
|
4
|
-
|
|
5
|
-
Creating and consuming an options page can be completed in a few steps:
|
|
6
|
-
|
|
7
|
-
1. Create a new Options Page — check out `backend/options.php` for some example code, noting that `show_in_graphql` must be set to `true`.
|
|
8
|
-
2. Create a new ACF field group, with the fields you need.
|
|
9
|
-
1. Set the Location Rule to `Options Page` `is equal to` `<your new options page>`.
|
|
10
|
-
2. Make sure `Show in GraphQL` is checked.
|
|
11
|
-
3. Set `GraphQL Field Name` to something short and sweet, using pascalCase, eg `myOptions`.
|
|
12
|
-
3. Check the GraphiQL IDE, and look for a root-level field with a similar name to the `menu_slug` defined in your PHP, code, eg. `themeGeneralSettings`. It should have a child field with you `GraphQL Field Name`, which contains your settings!
|
|
13
|
-
|
|
14
|
-
The PHP code should look something like this:
|
|
15
|
-
|
|
16
|
-
```php
|
|
17
|
-
acf_add_options_page([
|
|
18
|
-
'page_title' => 'Theme Settings',
|
|
19
|
-
'menu_title' => 'Theme Settings',
|
|
20
|
-
'menu_slug' => 'theme-general-settings',
|
|
21
|
-
'capability' => 'edit_posts',
|
|
22
|
-
'redirect' => false,
|
|
23
|
-
'show_in_graphql' => true
|
|
24
|
-
]);
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Assuming that all worked, you can then query these fields in an `.graphql` file. If it needs to be globally accessible, you can add it to the `_app.graphql` file, and access it using the `useAppData` hook. It'll even be typed with TypeScript.
|
|
28
|
-
|
|
29
|
-
```graphql title="views/_app.graphql"
|
|
30
|
-
query AppData {
|
|
31
|
-
themeGeneralSettings {
|
|
32
|
-
myOptions {
|
|
33
|
-
footerText
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
```tsx
|
|
40
|
-
const footerText = useAppData((data) => data?.themeGeneralSettings?.myOptions?.footerText)
|
|
41
|
-
```
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
# Bundle Size Tips
|
|
2
|
-
|
|
3
|
-
## Inspecting Bundle Size
|
|
4
|
-
|
|
5
|
-
You can quite easily see the production size of your app by running:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
yarn build
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
Above, we can see that the bundle size is 1.34mb, which is quite large. The note from Webpack says that we should aim for 244kb, which is really quite small. When we eventually move to serverless (via Vercel) for production frontends, we'll certainly aim for this smaller size. For now, with WordPress hosting, 600-700kb is fine. React itself takes up a bit of space on it's own.
|
|
14
|
-
|
|
15
|
-
Let's dig deeper into why the bundle is so large.
|
|
16
|
-
|
|
17
|
-
Our compile system includes the official [Webpack Bundle Analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer) plugin. You can get a detailed analysis of the bundle size using the following:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
yarn build
|
|
21
|
-
open dist/frontend/bundle-report.html
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Your browser will launch the bundle report, which will look something like this.
|
|
25
|
-
|
|
26
|
-

|
|
27
|
-
|
|
28
|
-
You can see in the example above, that `hls.js` and `moment` + `moment-timezone` are taking up _a lot_ of the bundle size.
|
|
29
|
-
|
|
30
|
-
What can we do about this?
|
|
31
|
-
|
|
32
|
-
## Choosing better libraries
|
|
33
|
-
|
|
34
|
-
In the example above, `moment` is taking up SO much space, for something that is so simple. There are much simpler and smaller libraries that can be used instead.
|
|
35
|
-
|
|
36
|
-
- If all you want is date formatting, check out `date-fns` — which provides a nifty date formatting function. The library is tree-shakable, meaning only the functions from that library you actually use in your code will be included in the bundle. [date-fns →](https://date-fns.org/)
|
|
37
|
-
- If you need something a little more powerful, or if you need something related to timezones, check out `luxon`, which is made by the same team that created `moment`. It's a much lighter alternative, because even though it supports timezones, it uses native browser APIs, instead of bundling info on every timezone/locale. [Luxon →](https://moment.github.io/luxon/index.html#/?id=luxon)
|
|
38
|
-
- (ps. Luxon doesn't come with TypeScript types, but you can install them using `yarn add --dev @types/luxon`)
|
|
39
|
-
|
|
40
|
-
It's always worth reconsidering the libraries we choose, looking for the most modern libraries for certain functions.
|
|
41
|
-
|
|
42
|
-
## Dynamic imports
|
|
43
|
-
|
|
44
|
-
Next up is `hls.js`. It's a library that provides a simple way to load and play HLS streams. It's not huge, but we probably don't need to include it in the main bundle.
|
|
45
|
-
|
|
46
|
-
Say we have the following code:
|
|
47
|
-
|
|
48
|
-
```tsx
|
|
49
|
-
import Hls from "hls.js"
|
|
50
|
-
|
|
51
|
-
// ...
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
const video = ref.current!
|
|
55
|
-
if (src) {
|
|
56
|
-
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
|
57
|
-
// HLS is already supported natively by this browser
|
|
58
|
-
video.src = props.url
|
|
59
|
-
} else {
|
|
60
|
-
// HLS is not supported by the browser. Use Hls.js instead!
|
|
61
|
-
const hls = new Hls()
|
|
62
|
-
hls.loadSource(props.url!)
|
|
63
|
-
hls.attachMedia(video)
|
|
64
|
-
return () => {
|
|
65
|
-
hls.destroy()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}, [src])
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
We can quite easily refactor this code to use dynamic imports, which will automatically split that library into it's own file, which will be imported separately only if/when it's needed. If we still need TypeScript types for the module, we can also use `import type` syntax, which will only import the types for TypeScript's sake, and not the module itself.
|
|
73
|
-
|
|
74
|
-
```tsx
|
|
75
|
-
import type Hls from "hls.js"
|
|
76
|
-
|
|
77
|
-
// ...
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
const video = ref.current!
|
|
81
|
-
if (props.url) {
|
|
82
|
-
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
|
83
|
-
// HLS is already supported natively by this browser
|
|
84
|
-
video.src = props.url
|
|
85
|
-
} else {
|
|
86
|
-
// HLS is not supported by the browser. Use Hls.js instead!
|
|
87
|
-
// Declare a reference to the object, so we can can still destroy it when the component transitions out
|
|
88
|
-
let hls: Hls
|
|
89
|
-
import("hls.js").then(({ default: Hls }) => {
|
|
90
|
-
// hls.js has been successfully dynamically imported.
|
|
91
|
-
// Assign to the `hls` variable, so that it can be destroyed properly
|
|
92
|
-
hls = new Hls()
|
|
93
|
-
hls.loadSource(props.url!)
|
|
94
|
-
hls.attachMedia(video)
|
|
95
|
-
})
|
|
96
|
-
return () => {
|
|
97
|
-
// Destroy the hls video, as long as it was created in the first place
|
|
98
|
-
if (hls) {
|
|
99
|
-
hls.destroy()
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}, [props.url])
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Dynamicly imported components
|
|
108
|
-
|
|
109
|
-
Similar to Next's `next/dynamic` [(link)](https://nextjs.org/docs/advanced-features/dynamic-import), we have our own `eddev/dynamic` function. This allows you dynamically load components from the `components/*` directory using dynamic imports.
|
|
110
|
-
|
|
111
|
-
```tsx title="blocks/homepage/some-block.tsx"
|
|
112
|
-
import { dynamic } from "eddev/dynamic"
|
|
113
|
-
|
|
114
|
-
const MyDynamicComponent = dynamic(() => import("@components/something/my-dynamic-component"))
|
|
115
|
-
|
|
116
|
-
export default defineBlock("homepage/some-block", () => {
|
|
117
|
-
return (
|
|
118
|
-
<div>
|
|
119
|
-
<p>I appear instantly</p>
|
|
120
|
-
<MyDynamicComponent fallback={<div>Loading...</div>} />
|
|
121
|
-
</div>
|
|
122
|
-
)
|
|
123
|
-
})
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
All the same props from `MyDynamicComponent` are available, and the fallback (which is optional) is added as a prop by the `dynamic` function. It'll show the fallback while the component is loading.
|
|
127
|
-
|
|
128
|
-
When using this feature, you may notice a flash while the component is being loaded, since your page will actually render without the dynamic component first. This means that it may not always be suitable if the component is typically "above the fold". You may want to consider showing a placeholder div, and/or fading in the component using an animation once it's loaded.
|
|
129
|
-
|
|
130
|
-
It's also important to note that the dynamic function expects (by default), a `default` export. Normally, we prefer to export named components, but in this case, `default` is good.
|
|
131
|
-
|
|
132
|
-
```tsx title="components/something/my-dynamic-component.tsx"
|
|
133
|
-
// BAD: export function MyDynamicComponent() {}
|
|
134
|
-
// GOOD:
|
|
135
|
-
export default function MyDynamicComponent() {
|
|
136
|
-
return <div>I'm a dynamic component!</div>
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Internally, we use `@loadable/components` — you can see other options for `dynamic` via their [docs](https://loadable-components.com/). Next also uses this library!
|
|
141
|
-
|
|
142
|
-
## Dynamically imported blocks
|
|
143
|
-
|
|
144
|
-
The `eddev/dynamic` function requires a tiny bit of boilerplate to get going. If you'd like to make a whole _block_ load dynamically, it's even easier. Note though that you wont be able to show a loading fallback.
|
|
145
|
-
|
|
146
|
-
Just add `Dynamic: true` to your block header comment — the compiler will spot this, and automatically turn it into a dynamic component. That's it!
|
|
147
|
-
|
|
148
|
-
```tsx title="blocks/homepage/some-block.tsx"
|
|
149
|
-
/**
|
|
150
|
-
* Title: Some Block
|
|
151
|
-
* Description: A block that does something cool
|
|
152
|
-
* Category: common
|
|
153
|
-
* Icon: book-alt
|
|
154
|
-
* Keywords: post
|
|
155
|
-
* Templates: default
|
|
156
|
-
* Types: page
|
|
157
|
-
* Mode: preview
|
|
158
|
-
* Supports multiple: true
|
|
159
|
-
* Tags: root
|
|
160
|
-
* Child Tags: none
|
|
161
|
-
* Dynamic: true
|
|
162
|
-
*/
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
^ The last line is the important part. You can read more about dynamic blocks [here](../gutenberg/dynamic-blocks).
|
|
166
|
-
|
|
167
|
-
## Validating the changes
|
|
168
|
-
|
|
169
|
-
In the top sections above, we swapped from `moment` to `luxon`, and we also made `hls.js` a dynamic import.
|
|
170
|
-
|
|
171
|
-
After running `yarn build` again, and checking out the visualizer, we can see that these two small changes have reduced our main bundle size by **HALF**.
|
|
172
|
-
|
|
173
|
-

|
|
174
|
-
|
|
175
|
-

|
|
176
|
-
|
|
177
|
-
We could take this even further if we wanted, by making any blocks which use Swiper dynamic blocks, as discussed above.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# Favicons
|
|
2
|
-
|
|
3
|
-
Since `eddev@0.2.0`, favicons are automatically included in every page, in both serverless and WordPress. All you need to do is export the icons straight from Figma!
|
|
4
|
-
|
|
5
|
-
## Exporting the icons
|
|
6
|
-
|
|
7
|
-
1. Navigate to the **🍒 oGraph & Icons** page in Figma
|
|
8
|
-
2. Select all the icons on the right
|
|
9
|
-
3. Activate the **Export** tab in the sidebar
|
|
10
|
-
4. Export with default settings to the `assets` folder in your theme.
|
|
11
|
-
5. Run `yarn dev` to regenerate the `favicon.ico` file, which is used as a fallback. The `<head>` is published automatically.
|
|
12
|
-
|
|
13
|
-
:::tip
|
|
14
|
-
See the bottom of this page for screenshots!
|
|
15
|
-
:::
|
|
16
|
-
|
|
17
|
-
## `favicon.ico`
|
|
18
|
-
|
|
19
|
-
When you run `yarn dev` or `yarn build`, a `favicon.ico` is automatically generated for you!
|
|
20
|
-
|
|
21
|
-
It uses the uses the pattern `assets/favicon/favicon-*.png`, which usually means it'll be composed using `favicon-16x16.png`, `favicon-32x32.png` and `favicon-96x96.png`.
|
|
22
|
-
|
|
23
|
-
## Light & Dark Mode Icons
|
|
24
|
-
|
|
25
|
-
Not all browsers support SVG favicons, but they're a great way to optionally support light/dark mode. You can right-click and 'Copy as SVG', and then add appropriate styling. Save to `assets/favicon/favicon.svg`, and it'll automatically be added to the `<head>` tag.
|
|
26
|
-
|
|
27
|
-
See below for an example:
|
|
28
|
-
|
|
29
|
-
```svg title="assets/favicon/favicon.svg"
|
|
30
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"
|
|
31
|
-
xmlns="http://www.w3.org/2000/svg">
|
|
32
|
-
<style>
|
|
33
|
-
path {
|
|
34
|
-
fill: #000000;
|
|
35
|
-
}
|
|
36
|
-
@media (prefers-color-scheme: dark) {
|
|
37
|
-
path {
|
|
38
|
-
fill: #ffffff;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
</style>
|
|
42
|
-
<path d="..." />
|
|
43
|
-
</svg>
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Meta Tags
|
|
47
|
-
|
|
48
|
-
The appropriate `<link />` tags are automatically added to your `<head>` tag, so you don't need to worry about it. Note that these tags only appear if they're found in the correct folder (`assets/favicon/`).
|
|
49
|
-
|
|
50
|
-
## Filenames
|
|
51
|
-
|
|
52
|
-
The following files are expected to be found. Note that if they are missing, there are no errors!
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
/assets/favicons/favicon.svg
|
|
56
|
-
/assets/favicons/120x120.png
|
|
57
|
-
/assets/favicons/128x128.png
|
|
58
|
-
/assets/favicons/196x196.png
|
|
59
|
-
/assets/favicons/apple-touch-icon-120x120.png
|
|
60
|
-
/assets/favicons/apple-touch-icon-152x152.png
|
|
61
|
-
/assets/favicons/apple-touch-icon-167x167.png
|
|
62
|
-
/assets/favicons/apple-touch-icon-180x180.png
|
|
63
|
-
/assets/favicons/favicon-16x16.png
|
|
64
|
-
/assets/favicons/favicon-32x32.png
|
|
65
|
-
/assets/favicons/favicon-96x96.png
|
|
66
|
-
/assets/favicons/windows-270x270.png
|
|
67
|
-
/assets/favicons/windows-70x70.png
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Screenshots of export steps
|
|
71
|
-
|
|
72
|
-
Select all the icons, skipping the labels:
|
|
73
|
-
|
|
74
|
-

|
|
75
|
-
|
|
76
|
-
Export your selection:
|
|
77
|
-
|
|
78
|
-

|
|
79
|
-
|
|
80
|
-
Your codebase should look like this after you've exported them. Note that if you instead see an `App icon` folder, you should rename this to `favicon` and ensure that it matches as below:
|
|
81
|
-
|
|
82
|
-

|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/docs_old/docs/intro.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Overview
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Config
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# WordPress + Vercel
|
|
2
|
-
|
|
3
|
-
WIP
|
|
4
|
-
|
|
5
|
-
- `SITE_URL` environment variable in Vercel
|
|
6
|
-
- `serverless.endpoints` option in `ed.config.json` — so that:
|
|
7
|
-
- Frontend code executed in WordPress can access API endpoints hosted on Vercel
|
|
8
|
-
- WordPress can redirect to the Vercel URL if WordPress is being used completely headless
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# APIs
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# RPC API
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# WordPress
|
|
6
|
-
|
|
7
|
-
There are several CMS' out there, and while WordPress may not be the most modern, it's very well known (both to clients and developers) and is easy to work with and host.
|
|
8
|
-
|
|
9
|
-
## Why not a cloud-based headless CMS + Next.js?
|
|
10
|
-
|
|
11
|
-
We use WordPress as a semi-headless CMS. While there are plenty of cloud-based headless CMS' out there, there are several issues with using them:
|
|
12
|
-
|
|
13
|
-
- They can be quite expensive!
|
|
14
|
-
- They often lack features we require, such as versioning, translation, ecommerce, user registration, user-submitted data, live preview and block-based content editing. These features are also often hidden behind an expensive 'Enterprise' plan.
|
|
15
|
-
- The lack of specific features often leads to the requirement of additional third-party platforms, which adds a great deal of complexity to our projects.
|
|
16
|
-
- Integrating them with frameworks like Next.js require lots of boilerplate code, which becomes hard to maintain.
|
|
17
|
-
- Next.js' file-based routing is great for web apps, but imposes limitations on URL customisation which are hard to overcome.
|
|
18
|
-
- We love our elegant page transitions, and these are harder to achive with Next.js.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 2
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Flywheel + Local
|
|
6
|
-
|
|
7
|
-
Our primary WordPress hosting provider is [Flywheel](https://getflywheel.com/). We have an organisation plan which allows us to host hundreds of WordPress sites, managed in an easy-to-use [dashboard](https://app.getflywheel.com/).
|
|
8
|
-
|
|
9
|
-
[Local](https://localwp.com/) is a desktop app which provides a development environment for WordPress sites, and was developed by Flywheel. It has useful 'sync' functionality, allowing you to push/pull files and the database between Local and a Flywheel site.
|
|
10
|
-
|
|
11
|
-
## Local Sync
|
|
12
|
-
|
|
13
|
-
Feel free to use Local Sync to deploy your WordPress site to Flywheel during the initial stages of development, however it's recommended that you use Github Actions to automate code deployment.
|
|
14
|
-
|
|
15
|
-
Pulling from Flywheel to Local is also a great way to pull down a site to work on it locally — just don't forget to re-clone the theme folder so that it's correctly linked to Git.
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 3
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# React
|
|
6
|
-
|
|
7
|
-
There's not much to say! React is great. It's particularly great for complex UI.
|
|
8
|
-
|
|
9
|
-
Be sure you're across React, hooks and how to use TypeScript with React. You should also probably know how Context works
|
|
10
|
-
|
|
11
|
-
- [React Hooks Guide on Smashing Magazine](https://www.smashingmagazine.com/2020/04/react-hooks-api-guide/) — goes over all the core hooks, as well as how to create custom hooks.
|
|
12
|
-
- [React & TypeScript: how to type hooks (a complete guide)](https://devtrium.com/posts/react-typescript-how-to-type-hooks) — learn by looking! Lots of examples and tips on how to correctly use hooks with TypeScript.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 4
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# TypeScript
|
|
6
|
-
|
|
7
|
-
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. We use TypeScript to write code that is easier to read and understand, although it is not as fast as JavaScript.
|
|
8
|
-
|
|
9
|
-
Some resources:
|
|
10
|
-
|
|
11
|
-
- [TypeScript — The Basics](https://www.youtube.com/watch?v=ahCwqrYpIuM) (video)
|
|
12
|
-
- [TypeScript with React](https://www.notion.so/ed-studio/ED-Stack-2021-Tour-7f50bc455d95403ebdff9a4503a78aee#b15ee6c11d40449e8f18b9ff19301901) (Udemy course)
|
|
13
|
-
- [React & TypeScript: how to type hooks (a complete guide)](https://devtrium.com/posts/react-typescript-how-to-type-hooks) — learn by looking! Lots of examples and tips on how to correctly use hooks with TypeScript.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# (WP)GraphQL
|
|
2
|
-
|
|
3
|
-
"GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools." (from the [GraphQL Website](https://graphql.org/)).
|
|
4
|
-
|
|
5
|
-
The [WPGraphQL](https://www.wpgraphql.com/) plugin (which is actually installed in the theme with Composer, rather than a plugin), provides a GraphQL API for WordPress.
|
|
6
|
-
|
|
7
|
-
## Schemas
|
|
8
|
-
|
|
9
|
-
GraphQL requires a server to be running to serve the queries. The WPGraphQL plugin provides a server that can be accessed at the URL `/graphql`, or via the `graphql()` PHP function.
|
|
10
|
-
|
|
11
|
-
The schema is automatically generated for you by the plugin, and makes all WordPress data available to you via queries.
|
|
12
|
-
|
|
13
|
-
You can define your own types and fields on the schema using the PHP functions documented on the [WPGraphQL website](https://www.wpgraphql.com/functions/).
|
|
14
|
-
|
|
15
|
-
## Queries
|
|
16
|
-
|
|
17
|
-
Queries are written in `.graphql` files, which can be stored in three locations in your code.
|
|
18
|
-
|
|
19
|
-
- `blocks/*/*.graphql`, alongside a block's `.tsx` file. Queries in these files will be run automatically by the server when the page is visited, and the data is passed as props to the block component. This allows blocks to query any other data on the site. Blocks can also query ACF fields defined on the block, via the global `block` field, which represents the current block being executed.
|
|
20
|
-
- `views/*.graphql`, alongside any View `.tsx` file. Just like blocks, the data is passed to the view's component. They can also use special variables to refer to the current post, or some querystring value.
|
|
21
|
-
- `queries/*.graphql`— these queries will have React hooks automatically generated for them, allowing the queries or mutations to be executed on demand by your React code. This is useful for components which need to perform searching/filtering/pagination, handle user data submissions, trigger server-side code etc.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Scripts
|
|
2
|
-
|
|
3
|
-
## `yarn dev`
|
|
4
|
-
|
|
5
|
-
The 'dev' command provides hot-reloading for multiple bundles — like frontend, admin and (eventually) serverless.
|
|
6
|
-
|
|
7
|
-
It's custom built, and made to be as clean as possible by showing issues relevant to the most recent attempt at a rebuild.
|
|
8
|
-
|
|
9
|
-
### Webpack
|
|
10
|
-
|
|
11
|
-
Internally, the system uses [Webpack](https://webpack.js.org/) and [webpack-dev-server](https://webpack.js.org/configuration/dev-server/), along with [react-refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin). Webpack configuration is _not editable_, and is auto-generated by the tool itself. We may swap Webpack out for another tool such as `swc` or `esbuild` at some point in the future for an additional speed boost, and so allowing access to Webpack config could result in compatibility issues.
|
|
12
|
-
|
|
13
|
-
For speed, each Webpack bundle runs in a separate worker thread, so that each bundle can compile concurrently, taking advantage of multiple CPU cores.
|
|
14
|
-
|
|
15
|
-
### GraphQL Codegen
|
|
16
|
-
|
|
17
|
-
The dev tool also provides realtime GraphQL -> TypeScript generation, by monitoring your project for changes and rebuilding when appropriate. For this, we're using [GraphQL Code Generator](https://www.graphql-code-generator.com/) with a host of custom plugins.
|
|
18
|
-
|
|
19
|
-
These files are _only_ generated by the dev tool, and not be the `yarn build` tooling. This only really matters for dynamic queries in the `queries/` folder. To be safe, you should always make sure `yarn dev` runs after editing a `.graphql` file in your project.
|
|
20
|
-
|
|
21
|
-
## `yarn build`
|
|
22
|
-
|
|
23
|
-
This produces production builds of the frontend and admin bundles, with tree shaking, minification and code-splitting.
|
|
24
|
-
|
|
25
|
-
It also produces a bundle sizing report, in `/dist/frontnend/bundle-report.html` — which you can use to see which dependencies are bloating up your bundle files. If a dependency is too large, consider dynamically importing it instead.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Aliases
|
|
2
|
-
|
|
3
|
-
There are a few import aliases predefined for you.
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
@components/* -> ./components/*
|
|
7
|
-
@hooks/* -> ./hooks/*
|
|
8
|
-
@utils/* -> ./utils/*
|
|
9
|
-
@theme -> ./theme.css.tsx
|
|
10
|
-
@queries -> ./hooks/queries.ts
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
This just means that you can use absolute paths to import your components and hooks etc, rather than having to use relative paths — making copy/pasting of import statements around your codebase a little bit easier.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Defines
|
|
2
|
-
|
|
3
|
-
There are a few globally accessible variables which you can access, which are defined via Webpack's `DefinePlugin`
|
|
4
|
-
|
|
5
|
-
From [Webpack configuration docs](https://webpack.js.org/plugins/define-plugin/):
|
|
6
|
-
|
|
7
|
-
> The `DefinePlugin` replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior between development builds and production builds. If you perform logging in your development build but not in the production build you might use a global constant to determine whether logging takes place. That's where DefinePlugin shines, set it and forget it rules for development and production builds.
|
|
8
|
-
|
|
9
|
-
The following variables are available:
|
|
10
|
-
|
|
11
|
-
- `process.dev` — `true` or `false`, depending on whether this bundle is targetting at dev mode or not.
|
|
12
|
-
- `process.admin` - `true` or `false`, depending on whether this bundle is used for the admin editor (Gutenberg) or on the frontend. Useful for rendering blocks for better editing experience.
|
|
13
|
-
- `process.themePath` - The relative URI pointing to the theme directory. Useful for calculating the location of assets. Note that there is NO trailing slash.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Config File
|
|
2
|
-
|
|
3
|
-
You'll find a `ed.config.json` file in the root of your theme folder. This file is read by both the `eddev` dev and build tool, along with the supporting `eddev-php` library.
|
|
4
|
-
|
|
5
|
-
Here are the options:
|
|
6
|
-
|
|
7
|
-
- `serverless` — An optional object.
|
|
8
|
-
- `enabled` — `true` or `false` — Controls whether serverless node is enabled for this project.
|
|
9
|
-
- `uploads` — `"proxy"` or `"remote"`
|
|
10
|
-
- `plugins` — `"proxy"` or `"remote"`
|
|
11
|
-
- `theme` — `"proxy"`, `"remote"` or `"copy"`
|
|
12
|
-
- `devAssets` — an optional array of glob paths or file names, relative to the theme folder, which are necessary for the frontend — this includes `assets/**` by default.
|
|
13
|
-
|
|
14
|
-
You can also find the original schema file [here](https://github.com/ed-digital/eddev/blob/main/src/config/config-schema.ts).
|