Created
May 5, 2021 20:04
-
-
Save Lexicality/fefe952f22a0f9622e47d995a4a7a7c1 to your computer and use it in GitHub Desktop.
Foundry with Webpack example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jpg goes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { preloadTemplates, getPartial } from "@/templates"; | |
Hooks.once("init", async function () { | |
Handlebars.registerHelper("partial", getPartial); | |
// Preload templates. | |
await preloadTemplates(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TEMPLATES = require.context("templates/", true, /\.html$/, "sync"); | |
export function preloadTemplates() { | |
// Use Webpack trickery to get the filenames for the templates | |
return loadTemplates(TEMPLATES.keys().map(TEMPLATES) as string[]); | |
} | |
export function getPartial(partialName: string) { | |
return TEMPLATES(`./parts/${partialName}.html`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.foo { | |
background: url("images/foo.jpg") repeat; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="foo"> | |
{{> (partial "example_part") name="foo"}} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, {name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "example", | |
"esmodules": ["dist/main.js"], | |
"styles": ["dist/main.css"], | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env node */ | |
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); | |
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin"); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
/** @type {import("webpack").Configuration} */ | |
module.exports = { | |
mode: "production", | |
devtool: "source-map", | |
entry: ["scripts/index.ts", "styles/index.scss"], | |
output: { | |
clean: true, | |
publicPath: "/systems/example/dist/", | |
// assetModuleFilename: "[path][name][ext]", | |
assetModuleFilename: (p) => p.filename.replace("src/", ""), | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(t|j)s$/, | |
use: "ts-loader", | |
exclude: /node_modules/, | |
}, | |
{ | |
test: /\.scss$/, | |
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"], | |
}, | |
{ | |
test: /\.(png|jpe?g|gif|svg|html)$/, | |
type: "asset/resource", | |
}, | |
], | |
}, | |
resolve: { | |
modules: ["node_modules", "src"], | |
extensions: [".ts", `...`], | |
alias: { | |
"@": "scripts", | |
}, | |
}, | |
plugins: [new MiniCssExtractPlugin()], | |
optimization: { | |
minimizer: [ | |
`...`, | |
new CssMinimizerPlugin(), | |
new HtmlMinimizerPlugin({ | |
minimizerOptions: { | |
customAttrSurround: [[/\{\{#[^}]+\}\}/, /\{\{\/[^}]+\}\}/]], | |
// ignoreCustomFragments: [/\{\{.+?\}\}/], | |
}, | |
}), | |
], | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment