Skip to content

Commit

Permalink
fix htmlOption
Browse files Browse the repository at this point in the history
  • Loading branch information
ereminnf committed Dec 1, 2021
1 parent 8ed4106 commit 356c641
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions htmlPlugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const generateGlobPath = require("./src/getFiles.js");
const fs = require("fs");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const generateGlobPath = require("./src/getFiles.js");
const path = require('path');
const NunjucksPlugin = require("./src/nunjucksPlugin.js");

Expand All @@ -27,7 +27,7 @@ function htmlPlugin(opt, htmlOpt, njkOption) {
inject: false,
chunks: {},
filename: ''
}, htmlOpt);
}, htmlOpt || {});

const pageFolderName = path.basename(options.pagesPath);

Expand All @@ -52,22 +52,23 @@ function htmlPlugin(opt, htmlOpt, njkOption) {
});

pages = pages.map(page => {
let chunks = htmlOption.chunks[page.name];
const opt = { ...htmlOption };
let chunks = opt.chunks[page.name];

if (chunks) {
chunks.push(page.name);
}

if (page.name === 'index') {
htmlOption.filename = `${options.outputPath}/index.html`;
opt.filename = `${options.outputPath}/index.html`;
} else {
htmlOption.filename = `${options.outputPath}${page.pathToBuild}index.html`;
opt.filename = `${options.outputPath}${page.pathToBuild}index.html`;
}

htmlOption.template = path.join(`${options.pagesPath}${page.pathToBuild}`, 'index.njk');
htmlOption.chunks = chunks;
opt.template = path.join(`${options.pagesPath}${page.pathToBuild}`, 'index.njk');
opt.chunks = chunks;

return new HtmlWebpackPlugin(htmlOption);
return new HtmlWebpackPlugin(opt);
})

pages.push(new NunjucksPlugin({
Expand Down

0 comments on commit 356c641

Please sign in to comment.