Skip to content

Commit

Permalink
Add overrides for HtmlWebpackPlugin #12
Browse files Browse the repository at this point in the history
  • Loading branch information
qrac committed Aug 25, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent fbddd1b commit 8b4f936
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -22,12 +22,28 @@ process.env.NODE_ENV = isDev ? "development" : "production"
const webpack = require("webpack")
const { merge } = require("webpack-merge")
const webpackDevServer = require("webpack-dev-server")
const HtmlWebpackPlugin = require("html-webpack-plugin")

const webpackConfig = require("./webpack.config")
const userWebpackConfig = fs.existsSync(path.resolve("webpack.config.js"))
? require(path.resolve("webpack.config"))
: {}
const mergedWebpackConfig = merge(webpackConfig, userWebpackConfig)

const htmlPlugins = mergedWebpackConfig.plugins.filter(
(plugin) => plugin.constructor === HtmlWebpackPlugin
)
const otherPlugins = mergedWebpackConfig.plugins.filter(
(plugin) => plugin.constructor !== HtmlWebpackPlugin
)
const mergedHtmlPlugins = [
...new Map(
htmlPlugins.map((plugin) => [plugin.userOptions?.template, plugin])
).values(),
]
const mergedPlugins = [...mergedHtmlPlugins, ...otherPlugins]
mergedWebpackConfig.plugins = mergedPlugins

const webpackCompiler = webpack(mergedWebpackConfig)
const devServerOptions = Object.assign({}, mergedWebpackConfig.devServer)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "minista",
"description": "Mini static site generator that can be written in React (JSX) for web coding",
"version": "0.9.6",
"version": "0.10.0",
"bin": {
"minista": "cli.js"
},

0 comments on commit 8b4f936

Please sign in to comment.