1

I'm integrating an external JS library (timbre.js) into a Haxe / OpenFL project. Right now I'm just injecting calls to the library using the untyped keyword, like this:

untyped T("sin").play();

then I build the html5 ... but I have to insert this line manually into index.html, before the line that embeds the .js file created by openfl:

<script type="text/javascript" src="./lib/timbre.js"></script>

I would have guessed that there's a way to have openfl create this line automatically by some tag in the project.xml file, but I've failed to discover a way of doing this. Or would it be something in Main.hx itself?

2 Answers 2

1

You can override the index.html template in your project.xml file.

Something like: <template path="custom_index.html" rename="index.html" />

The template file is here: openfl/templates/html5/template/index.html Copy it to your project folder and edit it.

Here is the full documentation In the Additional tags section.

Sign up to request clarification or add additional context in comments.

1 Comment

That works, thanks! In the template you directed me to, there is an iteration using a format that I don't recognize, with a lot of colons, something like ::if linkedLibraries::::foreach (linkedLibraries):: I suppose that might be a clue for another way to do this. But for my purposes this solution is fine.
0

<dependency /> tag is designed for this. There are three options:

  1. Ship the library with your project as a separate file:

    <dependency path="js-libs/someLibrary.js" />
    

    js-libs/someLibrary.js file will be copied to lib directory of the compiled project.

  2. Embed the library:

    <dependency path="js-libs/someLibrary.js" embed="true"/>
    

    The content of js-libs/someLibrary.js will be embedded into compiled application's .js file.

  3. Add remote link to the library:

    <dependency name="https://unpkg.com/[email protected]/simplepeer.min.js" />
    

The resulted index.html will have an appropriate <script> tag.

NOTE: This is not in the Lime/OpenFl doc but there is a PR to fix it.

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.