2

I'm having the following code:

<script data-main="scripts/main" src="components/requirejs/require.js"></script>
<script src="scripts/example1.js"></script>

Inside example1 I'm doing a require for some components of which the path is supposed to be set in scripts/main. However, the path is not correctly set (judging by the console feedback) which leads me to believe that require.js hasn't finished loading files referenced in scripts/main.

This all is pretty logical (async and all that), but I'd like to know how to run code inside example1.js after all this is set-up.

Normally, one would simply add the app-init code to scripts/main probably and be done with it, but I'm building up some examples, which all share the same scripts/main file (which is pretty big) and I don't want to duplicate that effort.

So how to do this?

1

1 Answer 1

1

Ended up doing the following, which isn't ideal (sets a global), but it's ok for my examples.

 <!-- sets window.requireconfig with an json object defining paths, etc.-->
 <script src="scripts/requireconfig.js"></script> 

 <!-- in top of example1.js do : require.config(window.requireconfig); -->
 <script data-main="scripts/example1" src="components/requirejs/require.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.