# Add a script to Discourse's webpack

**URL:** https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394
**Category:** Development
**Tags:** unsupported-install
**Created:** [July 1, 2024, 4:40am UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394 "2024-07-01T04:40:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [July 1, 2024, 4:40am UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/1 "2024-07-01T04:40:04Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/3/f/43f9264be36a85da88177581157fe6660a4dd882.png)

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?

```sh
/var/discourse$ ls
shared

```

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [July 1, 2024, 4:27pm UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/3 "2024-07-01T16:27:03Z")

</div>

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.

> [@darkpixlz](#):
>
> 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

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

> [@darkpixlz](#):
>
> I have a Discourse install running off an IP, which is “unsupported”

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

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [July 1, 2024, 5:40pm UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/4 "2024-07-01T17:40:04Z")

</div>

> [@david](#):
>
> Instead, you can create an initializer in a Discourse theme/plugin, and use that to run the `loadSprites()` code.

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

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [July 1, 2024, 6:45pm UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/5 "2024-07-01T18:45:29Z")

</div>

This topic has an example: [Split up theme Javascript into multiple files](https://meta.discourse.org/t/split-up-theme-javascript-into-multiple-files/119369)

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [July 1, 2024, 7:02pm UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/6 "2024-07-01T19:02:23Z")

</div>

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)

[https://github.com/darkpixlz/discourse-icons-fix](https://github.com/darkpixlz/discourse-icons-fix)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [July 31, 2024, 7:02pm UTC](https://meta.discourse.org/t/add-a-script-to-discourses-webpack/314394/7 "2024-07-31T19:02:31Z")

</div>

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