aboutsummaryrefslogtreecommitdiff
path: root/src/atlas-plugin.js
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2025-06-13 13:42:21 -0500
committerTim Keller <tjk@tjkeller.xyz>2025-06-13 13:42:21 -0500
commitb4d0b0293812afba9637c7e636bfa51366a030f7 (patch)
tree93b9e2d5ce841b76f5c41741a8ebca4a745571b0 /src/atlas-plugin.js
parent4154e0cc1744996788b6727cd2ef4a0d3a42095e (diff)
downloadmaterial-svg-atlas-plugin-webpack-b4d0b0293812afba9637c7e636bfa51366a030f7.tar.xz
material-svg-atlas-plugin-webpack-b4d0b0293812afba9637c7e636bfa51366a030f7.zip
cleanup package and fix bug from not importing fs/path in utils
Diffstat (limited to 'src/atlas-plugin.js')
-rw-r--r--src/atlas-plugin.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/atlas-plugin.js b/src/atlas-plugin.js
new file mode 100644
index 0000000..69f1174
--- /dev/null
+++ b/src/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