Add a script to Discourse's webpack

Hello,

I’ve never worked with webpack and my JS knowledge is poor, and I have a Discourse install running off an IP, which is “unsupported”. It works, but the icons are missing because it tries loading http://192.168.0.22:8080/svg-sprite/192.168.0.22:8080/svg-3-c1066beb12cc75cc4c3bc42f218f381c862e7905.js which has the icons, but failed because of the numbers. Anything else would work, such as http://192.168.0.22:8080/svg-sprite/-/svg-3-c1066beb12cc75cc4c3bc42f218f381c862e7905.js (you can put anything where the - is so I’m not quite sure why it exists in the first place but thats not up for me to decide).

I’m trying to get it to load the correct host, so I made a little script to do it, but thanks to webpack I’m not able to access the loader through imports:

Because of this limitation, I need to get into discourse’s webpack which is nowhere to be found. How can I add a script to the folder?

/var/discourse$ ls
shared

We don’t use the browser’s native module resolution system, so <script type="module"> with imports and exports won’t work as you expect.

Instead, you can create an initializer in a Discourse theme/plugin, and use that to run the loadSprites() code.

It’s for hosting environments where the same CDN domain is used by multiple Discourse forums.

Indeed… it is not supported. You are very likely to run into other issues.

2 Likes

Is there a guide for this? Haven’t tried that before.

This topic has an example: Split up theme Javascript into multiple files

1 Like

Thanks… it worked! For anybody else having this issue in the future, here’s the repo which I used to fix it (assuming you are running on 192.168.0.22:8080)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.