Custom template and bundling

There’s missing documentation on how to do this.
I’m not sure if it assumes a base level of knowledge of web development because

I’m trying to use parcel with react. I’ve created an npmdef and configured as much as I thought was necessary - I’ve copied and pasted stuff from the react template made by needle.

I’m not sure what to then do with it? I’ve tried adding the npmdef in the dependencies list in the ExportInfo component, but that will still build the default vite template

Also, when I start a new scene, and add the ExportInfo component, I no longer get an option to choose from a template, so I’m not sure what has changed there.

This page seems to have the bare minimum: Frameworks, Bundlers, HTML | Needle Engine Documentation

" Select Create/Needle Engine/Project Template to add a ProjectTemplate into the folder you want to use as a template

Done! It’s that simple."

I’m really not sure what that means - I’ve tried that but it’s clear there are more steps and configuration required

I have the Pro License - I am not sure if this is the correct avenue for asking questions

Thanks

Original Post on Discord

by user 285903863339548673

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

Hi, can you briefly explain what your goal is? Do you want to create a custom web project template that you can re-use for multiple projects and to quickly spin up a new project using that template? Or is your goal to just use your “parcel with react” web project?

you dont see this when you add ExportInfo to a new GameObject?
Capto_Capture_2023-12-30_08-09-12_PM.png

Hi, thanks for getting back.

I’d like to to be able to the former: spin up a new project with that template. (parcel + react)

In general I’m trying to understand and learn how the web project is put together, so wanted to try making my own web project setup

I can now select a template in the ExportInfo component ( It wasn’t working before because I had to create a new Project Folder, duh)

When I try to generate the project, it complains there is no package.config, even though there is one

by user 285903863339548673

by user 285903863339548673

So there are two options for how/where to manage your project templates.

Option A your web project is inside Unity Assets or a local Unity package (this can of course also be on github) - in which case you put the ProjectTemplate scriptable object inside the directory that has your web project (make sure to not install it - you dont want to have a node_modules folder in Unity)

Option B (which i would recommend) - is to create a separate github repository for your web project which just contains the web project (and which you just reference via the Remote Url inside the “Project Template” scriptable object in Unity)

  1. Select your parcel/react project in the ExportInfo component with the “Pick” button and make sure it starts/runs as expected (the directory needs to contain a package.json). The Unity package will generate a needle.config file which you can use to configure where to export your GLB files to and where your scripts, which directory is the output directory etc

  2. Once your project runs as expected I would create a github repository and push the project to that repo. In Unity you can then (if you want to spin up a new web project using your template) just paste the github URL into the ExportInfo “Directory” field (it will recognize the github url and give you an option to clone it) OR you can create a new Project Template scriptable object (the one you sent a screenshot above) and paste the github URL in “Remote Url” field in which case your custom template will show up in the ExportInfo templates dropdown

Our sveltekit template for example is always pulled from github when you create a new project with it GitHub - needle-engine/sveltekit-sample: Sveltekit with Needle Engine Sample + automatic deployment to github pages

you can have a look at how we manage our templates here:

The only one that ships with the Unity project still is the Vite template - all other templates are pulled from github when selected

What you did above is basically telling the package that your whole Assets folder is a web project template. Thats why its not working and surely not your intention. The inspector should be more clear about that!!!

Npmdefs should be used to enhance a web project and add functionality/features, they are installed into a web project (just like a unity package is installed to a unity project)

Ok, thanks for the detailed response. I think I follow, but haven’t yet tried it - I will come back to you shortly!

Although I don’t understand what the Npmdef is for then? I am following the Needle Docs guide and it refers to them. I’ve made one, and have configured the package.json. What do I do with it then?

EDIT: just saw your last message

by user 285903863339548673

I hope this helps. You create them to split and manage your project into modular parts that you can add or remove to any web project. What exactly you put inside them is up to you and you dont have to use them at all if you dont want/need to.

For example our samples have multiple npmdefs that contain different scripts (or reference other packages from npm) that we add/remove to the vite template per sample (if the sample needs it)

That way our vite template stays minimal and doesnt have dependencies you might not want or need. And the same code can be added to sveltekit or react…

Ok, I think I’m getting there. Although now I get this error:

I’m literally pasting over files from the react template, which I have running no problem

by user 285903863339548673

Maybe the react template is missing this part

Cool - that works.

Now when I add the:

I add src = "./assets/myScene.glb"

But it doesn’t appear to load. There are not warnings in the console :frowning_with_open_mouth:

Clutching at straws here…

by user 285903863339548673

by user 285903863339548673

Seems like your HTML element has a size of 0


by user 285903863339548673

I’ve given it some styling to prove it’s there but it’s still not rendering anything

the component will load into the DOM. However when i wrap it as a react component, as per the Needle React Template, it doesn’t appear on the DOM

by user 285903863339548673