The theme used for the Xo for Angular documentation site.
Use ng serve
to rapidly develop locally, taking advantage of file watching to compile and reload the development site. Use ng build
to create a distribution and let Xo serve the site through the main domain without any additional server setup.
Once the theme has been built using ng build
or ng build --prod
the source folders are no longer necessary. A theme developer may opt to publish a theme built with Xo that does not include the source or build tools.
This theme comes compiled for production so all assets and application code are the minimal (fastest) size.
- Download the latest Xo for Angular from the releases page, upload, and activate within WordPress.
- Download the latest Xo Material theme from the releases page, upload, and activate within WordPress.
- Create menus, pages, posts, and other content and let Xo do the heavy lifting.
This theme also makes use of ACF Pro, a fantastic plugin for adding configurable fields to various items within WordPress such as pages, posts, menus, etc. Without ACF installed only the default template is usable as it only makes use of the wordpress default editor.
-
Rebuild the Xo Templates Cache. Depending on the order in which the theme and plugin were installed/activated or if template changes have occured it will be necessary to rebuild the cache of templates within WordPress
- From the Xo -> Tools main tab click the "Rebuild Templates Cache" button.
- This is not necessary if the Reader or Cache are disabled from the Xo -> General Options -> Templates tab.
-
Set the Redirect Mode on the Xo -> General Options -> Index to Live and Save.
- Check that the Src Index is set as
/src/index.html
. - Lastly check that the Dist Index is set as
/dist/index.html
.
- Check that the Src Index is set as
-
Using the Live Redirect Mode allows WordPress and other plugins to inject code and content in your theme. Options to include this and the App Config are found under the Live Index section on the Xo -> General Settings -> Index tab.
- Check that that the App Config is enabled, this is necessary to instruct the Angular App about the location of the Xo API and other WordPress or theme settings.
- Optionally enable Header (wp_head) and Footer (wp_footer) to be included in the index. This theme does not use wp_footer and if not required by other plugins should be disabled to save on performance.
This theme additionally comes with all source files and configuration info necessary to develop, modify, and debug the Angular App running within the theme.
Just as your Angular App can run with ng serve
your WordPress will also need to run on a server. I recommend XAMPP for beginners, though the below should work for any apache server.
-
Download your entire WordPress installation and place the files at:
C:\Projects\AngularXoMat
. If the path does not exist, create theProjects
folder first and thenAngularXoMat
inside. This can be a path anywhere on your machine, inside should be theindex.php
file andwp-content
folder for example. Make sure if you have an.htaccess
file that it has been copied as well, sometimes this file is hidden depending on your view settings. -
Add a virtual DNS entry for
angularxo.local
. Otherwise the site must work at the root or sub folder oflocalhost
which can be messy when working on multiple projects. This entry will tell the browser that the data for this domain should come a server on our local machine.- Open notepad as Administrator.
- File -> Open ->
C:\windows\system32\drivers\etc\hosts
. - On a new line at the bottom add
127.0.0.1 angularxo.local
. - Save.
-
Add a virtual host entry in
httpd.conf
. This is necessary to pointangularxo.local
to our local WordPress directory atC:\Projects\AngularXoMat
.- Open notepad or your editor of choice.
- File -> Open ->
C:\xampp\apache\conf\httpd.conf
. - On a new line at the bottom add the below
<VirtualHost *:80> ServerName angularxo.local DocumentRoot "C:\Projects\AngularXoMat" <Directory "C:\Projects\AngularXoMat"> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> </VirtualHost>
- Save and restart apache.
-
Visit
http://angularxo.local
in your browser. Thehttp://
protocol portion is important as browsers such as Chrome may attempt to search for the unknown domain. Typing the protocol portion forces the browser to load the domain propertly.
It is possible to use the Angular CLI to build, modify, and add new modules and components. This theme comes with several shortcuts for running the ng serve
local development server and ng build
with the right arguments that are compatible with WordPress and Xo.
- First open a command prompt.
The easiest method as it makes use of your previously configured server to access your WordPress as normally through http://angularxo.local
. This can be accomplished using one of the following commands:
-
npm run build
orng build --deploy-url /wp-content/themes/angular-xo-material/dist/
- Run a build to the dist folder at
/wp-content/themes/angular-xo-material/dist/
. This is important as unlike a typical Angular App where the files in the/dist/
folder are deployed to the root of the server these files are actually nested within the theme folder in WordPress. - The Angular App will be in debug mode which may emit more verbose information on the console, additional resource map files, and assets and application files will not be minified.
- Run a build to the dist folder at
-
npm run deploy
orng build --prod --deploy-url /wp-content/themes/angular-xo-material/dist/
- The same as
npm run deploy
except assets and application code are minified with the Angular App configured for production.
- The same as
-
npm run watch
orng build --watch --deploy-url /wp-content/themes/angular-xo-material/dist/
- The same as
npm run deploy
except once the initial compilation is complete the script will be placed into a watch mode for file changes that may trigger recompliation. A refresh of the page is required to see the updated changes.
- The same as
Running with ng serve
we need a way to reference our local angularxo.local
server from within the live server typically running at localhost:4200
. This is made possible by adding an additional build configuration invoked by running the below command:
npm run serve
orng serve --configuration local
- Run
ng serve
and include the App Config specified in/src/environments/environment.local.ts
within the theme folder.
- Run
If you run the local WordPress server from a host other than angularxo.local
it is required that this be updated in the local environment file at /src/environments/environment.local.ts
within the theme folder.
This is necessary as Xo within WordPress will not have the opportunity to parse the index file and add this configuration dynamically using the Live Redirect Mode. Additionally it is possible to specify this configuration manually for the production environment file and use the faster Offline Redirect Mode.
All notable changes to this project.