electron-webpack
electron-webpack copied to clipboard
ejs not work 2.7.2+ but 2.6.2
- Version: 2.7.5
- Target:
ejs not work 2.7.2+ but 2.6.2
Here's a recipe for using an ejs file for the renderer template with additional template data. In webpack.renderer.js :
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { merge } = require('webpack-merge');
module.exports = function (config) {
const htmlPlugin = config.plugins.find((plugin) => plugin instanceof HtmlWebpackPlugin);
htmlPlugin.options.template = 'src/renderer/index.ejs';
const { templateParameters } = htmlPlugin.options;
// WARNING: not sure if the webpack merge function will handle partial configs properly
htmlPlugin.options.templateParameters = (...params) => merge(
{
isDev: process.env.NODE_ENV !== 'production',
electronHeadScript: `<script>
${htmlPlugin.nodeModules == null
? ''
: `require("module").globalPaths.push("${htmlPlugin.nodeModules.replace(/\\/g, '/')}")`}
require("source-map-support/source-map-support.js").install()
</script>`,
}, templateParameters(...params),
);
return config;
};
electron-webpack generates a template file .renderer-index-template.html before running webpack. Circumventing the use of the .renderer-index-template.html means that the scripts end up in the body of the document rather than in the head but this didn't seem to cause me any issues. Does anyone know why the electron-webpack index "template" adds the scripts to the head (webpack defaults to putting them in the body)? Circumventing .renderer-index-template.html also removes the inclusion of the source map support etc. from the document hence electronHeadScript.
The following markup was added to the head of the template:
<%= electronHeadScript %>
<% if (isDev) { %>
<!-- mobx devtools (standalone app) -->
<script src="//localhost:8098"></script>
<% } %>