Skip to content

Commit

Permalink
feat: inject title to viteHtmlPluginOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 7, 2021
1 parent 960d713 commit 3b34151
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-html",
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.4",
"description": "A plugin for vite to Minimize index.html and use lodash.template template syntax in index.html",
"main": "dist/index.js",
"files": [
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export default (opt: VitePluginHtml = {}): Plugin[] => {
transformIndexHtml: {
enforce: 'pre',
transform: async (html) => {
const { options = {} } = opt;
const { options = {}, title } = opt;

let compiledHtml = html;
try {
// Compile using lodash template syntax
// Expose options to the viteHtmlPluginOptions object
const compiled = template(compiledHtml);
compiledHtml = compiled({
viteHtmlPluginOptions: options,
viteHtmlPluginOptions: {
title,
...options,
},
});
} catch (error) {
console.error('Template compiled fail\n' + error);
Expand Down

0 comments on commit 3b34151

Please sign in to comment.