<div id="root"></div>
<script src="./index.js"></script>
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlBundlerPlugin = require("html-bundler-webpack-plugin");
module.exports = (env) => {
return {
resolve: {
extensions: [".tsx", ".jsx", ".ts", ".js"],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "./",
to: "resources",
filter: (file) => !file.endsWith(".jsx") && !file.endsWith(".html"),
},
],
}),
new HtmlBundlerPlugin({
filename: "[name].ftl",
entry: "./",
postprocess: (content) => {
return content.concat("<head></head>");
},
js: {
inline: true,
},
css: {
inline: true,
},
}),
{
apply(compiler) {
const pluginName = "inline-template-plugin";
compiler.hooks.compilation.tap(pluginName, (compilation) => {
const hooks = HtmlBundlerPlugin.getHooks(compilation);
hooks.beforeEmit.tap(pluginName, (content) => {
return (
'<#import "template.ftl" as layout>' +
"<@layout.registrationLayout displayInfo=social.displayInfo; section>" +
content +
"</@layout.registrationLayout>"
);
});
});
},
},
],
module: {
rules: [
{
test: /.(js|jsx|ts|tsx)$/,
use: {
loader: "babel-loader",
options: {
plugins: [["remove-comments"]],
presets: [["@babel/preset-env"], "@babel/preset-react"],
},
},
},
{
test: /.(js|jsx|ts|tsx)$/,
include: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /.(ts|tsx)$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(css|sass|scss)$/,
use: ["css-loader", "sass-loader"],
},
{
test: /\.(ico|png|jp?g|webp|svg)$/,
type: "asset/resource",
generator: {
outputPath: () => {
return "resources";
},
filename: ({ filename }) => {
const base = path.basename(filename);
return "/img/" + base;
},
},
},
{
test: /[\\/]fonts|node_modules[\\/].+(woff(2)?|ttf|otf|eot)$/i,
type: "asset/resource",
generator: {
outputPath: () => {
return "resources";
},
filename: ({ filename }) => {
const base = path.basename(filename);
return "/fonts/" + base;
},
},
},
],
},
output: {
clean: true,
publicPath: "public",
},
watchOptions: {
ignored: ["node_modules", "dist"],
},
cache: {
type: "memory",
cacheUnaffected: false,
},
devtool: false,
};
};