@trinitymirrordigital/cue-templates-plugin
This sets up a Webpack plug that creates the cue configuration yaml from JS comments
Installation
yarn add --dev @trinitymirrordigital/cue-templates-plugin
Config
Update your config.yml with the following:
default: &default
...
templates_path: template
yaml_output: /etc/escenic/cue-web
start_up_script: /usr/bin/startup.sh
...
Then in webpack config add the following
const { TemplatePlugin, getFiles } = require('@trinitymirrordigital/cue-templates-plugin');
const { webpackConfig, config } = require('@trinitymirrordigital/webpack-config');
const { merge } = require('webpack-merge');
const { env } = require('process');
const files = getFiles(config);
const {
cueUrl,
publicDevOutput,
publicOutputPath,
publicRootPath,
startUpScript,
yamlOutput,
} = config;
const publicPath = env.NODE_ENV === 'development' ? publicDevOutput : publicOutputPath;
module.exports = merge(webpackConfig, {
entry: { ...files },
plugins: [
new TemplatePlugin({
js: publicRootPath,
publicPath,
output: yamlOutput,
shellScript: startUpScript,
}),
],
new HtmlWebpackPlugin({
filename: htmlOutput,
alwaysWriteToDisk: true,
template: htmlTemplate,
excludeChunks: Object.keys(files),
}),
]
});
Shell script
As CUE requires the YAML files before starting it is important that the YML file are created before CUE has started. In production this is fine, however as the webpack-dev-server is always building we need to ensure they created first so you should add something like this too the entry.sh:
if [ "${ENVIRONMENT_NAME}" == "dev" ]
then
cd /var/www/html/cue-web && npm run webpack:server
else
cd /var/www/html/cue-web && npm run webpack && \
sed -i "s|CUE_URL|${CUE_URL}|" /etc/escenic/cue-web/config.yml
dpkg-reconfigure cue-web-3.7
/etc/init.d/content-duplication-service start
nginx -g "daemon off;"
rm -rf /var/www/html/cue-web/node_modules
fi
then in the start.sh
#!/usr/bin/env bash
unlink /var/log/nginx/error.log && unlink /var/log/nginx/access.log
sed -i "s|CUE_URL|${CUE_URL}|" /etc/escenic/cue-web/config.yml
echo 'adding CUE_URL'
dpkg-reconfigure cue-web-3.7
/etc/init.d/content-duplication-service start
service nginx start
Then in the webcomponet please add the following comment at the top of your file:
So yml-create let's the plugin know this is a for creating a yaml config, the name after is the name of the yaml file so this one will create bookmark.yml.
Then the config should be expressed in JSON, the exception is the file name:
FILE: [my - web - component - file];
This will allow webpack to replace with a the correct cache busted file.
Then add you config as a json string like so:
Copyright (c) 2019 "Reach Shared Services Ltd"