Allow custom HTML snippets in build

This commit is contained in:
Alex Gleason
2022-04-20 13:58:22 -05:00
parent 074a1a6fce
commit ed223a9ff6
3 changed files with 49 additions and 0 deletions

View File

@ -1,5 +1,6 @@
// Note: You must restart bin/webpack-dev-server for changes to take effect
const fs = require('fs');
const { join, resolve } = require('path');
const CopyPlugin = require('copy-webpack-plugin');
@ -16,6 +17,15 @@ const rules = require('./rules');
const { FE_SUBDIRECTORY, FE_INSTANCE_SOURCE_DIR } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
// Return file as string, or return empty string
const readFile = filename => {
try {
return fs.readFileSync(filename, 'utf8');
} catch {
return '';
}
};
const makeHtmlConfig = (params = {}) => {
return Object.assign({
template: 'app/index.ejs',
@ -30,6 +40,9 @@ const makeHtmlConfig = (params = {}) => {
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
templateParameters: {
snippets: readFile(resolve('custom/snippets.html')),
},
}, params);
};