aboutsummaryrefslogtreecommitdiff
path: root/atlas-plugin.js
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2025-05-23 14:22:55 -0500
committerTim Keller <tjkeller.xyz>2025-05-23 14:22:55 -0500
commite01a5e79337f31e656ed6d87c3cc168a06f0f27a (patch)
tree7c3dd29f72627488dbe810847083bbed925b95e4 /atlas-plugin.js
parent364f239918c6ef3f110a437aab2bab0891337563 (diff)
downloadmaterial-svg-atlas-plugin-webpack-e01a5e79337f31e656ed6d87c3cc168a06f0f27a.tar.xz
material-svg-atlas-plugin-webpack-e01a5e79337f31e656ed6d87c3cc168a06f0f27a.zip
material symbols plugin added. Cleanup more make better
Diffstat (limited to 'atlas-plugin.js')
-rw-r--r--atlas-plugin.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/atlas-plugin.js b/atlas-plugin.js
new file mode 100644
index 0000000..69f1174
--- /dev/null
+++ b/atlas-plugin.js
@@ -0,0 +1,36 @@
+const fs = require("fs")
+const path = require("path")
+const { RawSource } = require("webpack-sources")
+const { generateAtlasViews } = require("./utils.js")
+
+
+class SVGSymbolAtlasViewPlugin {
+ constructor(options = {}) {
+ this.suffix = options.suffix || ".svg"
+ this.symbolId = options.symbolId || null
+ }
+
+ apply(compiler) {
+ compiler.hooks.thisCompilation.tap("SVGSymbolAtlasViewPlugin", (compilation) => {
+ compilation.hooks.processAssets.tap(
+ {
+ name: "SVGSymbolAtlasViewPlugin",
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
+ },
+ (assets) => {
+ for (const assetName in assets) {
+ if (assetName.endsWith(this.suffix)) {
+ const originalSVG = assets[assetName].source().toString()
+ const atlasSVG = generateAtlasViews(originalSVG, this.symbolId)
+
+ // Replace old SVG asset with new SVG
+ compilation.updateAsset(assetName, new RawSource(atlasSVG))
+ }
+ }
+ }
+ )
+ })
+ }
+}
+
+module.exports = SVGSymbolAtlasViewPlugin