Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Use HtmlWebpackPlugin to inject html during webpack build #302

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ Thumbs.db

/dist
/temp

# ignore everything in 'app' folder what had been generated from 'src' folder
/app/app.js
/app/background.js
/app/**/*.map
/app
27 changes: 24 additions & 3 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const path = require("path");
const jetpack = require("fs-jetpack");
const nodeExternals = require("webpack-node-externals");
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');

const translateEnvToMode = (env) => {
if (env === "production") {
Expand All @@ -9,6 +11,12 @@ const translateEnvToMode = (env) => {
return "development";
};

const getAllHtmlFilesInSrcDir = () => {
const srcDir = jetpack.cwd('src');
return srcDir.find({ matching: '*.html', recursive: false })
.map(path => path.split('.').slice(0, -1).join('.'));
};

module.exports = env => {
return {
target: "electron-renderer",
Expand Down Expand Up @@ -37,8 +45,21 @@ module.exports = env => {
}
]
},
plugins: [
new FriendlyErrorsWebpackPlugin({ clearConsole: env === "development" })
]
plugins: (() => {
const plugins = [
new FriendlyErrorsWebpackPlugin({ clearConsole: env === "development" }),
];

getAllHtmlFilesInSrcDir().map(fileName =>
plugins.push(
new HtmlWebpackPlugin({
filename: `${fileName}.html`,
template: `src/${fileName}.html`,
chunks: [ fileName ]
})
)
)
return plugins;
})()
};
};
Loading