Skip to content

Instantly share code, notes, and snippets.

@davecra
Created October 22, 2023 20:04
Show Gist options
  • Save davecra/21cbcb08a427dada98eed9f338b3ca21 to your computer and use it in GitHub Desktop.
Save davecra/21cbcb08a427dada98eed9f338b3ca21 to your computer and use it in GitHub Desktop.
Webpack.config.js for Power-Up
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const fs = require("fs");
module.exports = async (env, options) => {
const isProduction = options.mode === 'production';
const config = {
devtool: isProduction ? false : 'source-map',
mode: isProduction ? "production" : "development",
entry: {
details: "./js/details.js",
client: "./js/client.js",
},
output: {
devtoolModuleFilenameTemplate: "webpack:///[resource-path]?[loaders]",
clean: true,
},
resolve: {
extensions: [".ts", ".tsx", ".html", ".js"],
},
module: { },
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: "./views/index.html",
chunks: ["client"],
}),
new HtmlWebpackPlugin({
filename: "details.html",
template: "./views/index.html",
chunks: ["details"],
}),
],
devServer: {
hot: true,
headers: {
"Access-Control-Allow-Origin": "*",
},
https: env.WEBPACK_BUILD || options.https !== undefined ? options.https : {
key: fs.readFileSync('./certs/server.key'),
cert: fs.readFileSync('./certs/server.crt'),
},
port: process.env.npm_package_config_dev_server_port || 12345,
},
};
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment