From a30b28d40e5bacdbbbcad3c9de8f1fe3e083119c Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 14 Feb 2023 09:46:34 +0530 Subject: Added ability to load static assets from extension's assets. --- .../plugins/create-manifest-webpack-plugin/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'config/webpack/plugins/create-manifest-webpack-plugin') diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index 3a16770..a1a21a8 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -14,7 +14,7 @@ class CreateManifestPlugin { stage: compiler.webpack.Compilation.PROCESS_ASSETS_ADDITIONAL, additionalAssets: true }, - () => { + assets => { const scripts = formatScripts(require(path.resolve(SOURCE_DIR, "scripts.json"))); const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json"); manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version; @@ -30,6 +30,23 @@ class CreateManifestPlugin { } } + const resources = []; + + for (const assetName in assets) { + if (/^assets\/.*\.(jpg|png|gif)$/.test(assetName)) { + resources.push(assetName); + } + } + + if (resources.length > 0) { + manifest.web_accessible_resources = [ + { + resources, + matches: [ "" ] + } + ]; + } + compilation.emitAsset( "manifest.json", new sources.RawSource(JSON.stringify(manifest)) -- cgit v1.2.3