Files
ESP3D-Configurator/config/webpack.prod.js
Luc 27e16d9421 Add context help for choice
Add more rendering in configuration.h
2022-06-14 09:36:47 +08:00

87 lines
2.9 KiB
JavaScript

const path = require("path")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin")
const HtmlInlineScriptPlugin = require("html-inline-script-webpack-plugin")
const HTMLInlineCSSWebpackPlugin =
require("html-inline-css-webpack-plugin").default
const Compression = require("compression-webpack-plugin")
module.exports = {
mode: "production", // this trigger webpack out-of-box prod optimizations
entry: path.resolve(__dirname, "../src/index.js"),
output: {
filename: `[name].[hash].js`, // [hash] is useful for cache busting!
path: path.resolve(__dirname, "../build"),
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{
loader: "css-loader",
options: {
sourceMap: false,
},
},
{
loader: "sass-loader",
options: {
sourceMap: false,
},
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["preact"],
},
},
],
},
],
},
plugins: [
// always deletes the dist folder first in each build run.
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "../src/index.html"),
inlineSource: ".(js|css)$",
inject: "body",
}),
new HtmlInlineScriptPlugin([/\.(js)$/]),
new HTMLInlineCSSWebpackPlugin(),
],
optimization: {
minimize: true,
minimizer: [
new HtmlMinimizerPlugin({
minimizerOptions: {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
},
minify: (data, minimizerOptions) => {
const htmlMinifier = require("html-minifier-terser")
const [[filename, input]] = Object.entries(data)
return htmlMinifier.minify(input, minimizerOptions)
},
}),
],
},
devtool: "source-map", // supposedly the ideal type without bloating bundle size
}