Importing an npm package into a foundry system

import minimist from 'minimist'; That line alone when included in my module's hook file is resulting in the system breaking. Do we need to include webpack/Vite/or something of the sort? Why isn't the software handling this automatically? Is there a tutorial we can follow?
E
Eranziel157d ago
It Depends. ™️ It is possible to import an npm dependency if it's present in the system code in Foundry data and your import path is correct. Basically the same as any other import you do in your entry point. That said, I strongly advise against including your entire npm_modules folder in your distribution zip. By the nature of npm it easily bloats to a gigantic size. So, yes, I'd recommend a bundler. A Foundry system is client-side browser code, exactly what bundlers are made for. Foundry doesn't do bundling for systems/modules because there's (excellent) existing tools for that and it's wildly outside of the scope of a self-hosting app to try to auto bundle code for its extensions.
E
Eranziel157d ago
Here's a tutorial for using Vite for Foundry: https://foundryvtt.wiki/en/development/guides/vite
Foundry VTT Community Wiki
Using Vite to build for Foundry
everything you ever wanted from hot module replacement but were afraid to ask
E
Eranziel157d ago
It may be slightly out of date, so take with a grain of salt of course.
M
mfi157d ago
@Eranziel Thank you for the pointers/advice
LTL
Leo The League Lion157d ago
@mfi gave vote LeaguePoints™ to @Eranziel (#132 • 10)
M
mfi157d ago
For the time being, and since this system is more home-brew than anything, I am going to go with a browserify setup. I was under the impression that FoundryVTT would (in its backend) handle hosting npm code up as necessary to the frotnend, but I was wrong. Oh well
TM
TyphonJS (Michael)157d ago
I highly recommend avoiding Browserify as it is more or less defunct. It was an early bundler tool, but is firmly replaced / not current gen. If you don't have any experience w/ Browserify then it makes more sense to work w/ Vite, but for focused / minimal bundling Rollup is strong. Vite currently uses Rollup under the hood for production builds. Both Vite and Rollup are actively developed whereas Browserify is not.
E
Eranziel157d ago
I mean, Foundry will only serve files that you reference. The client browser won't download everything in npm modules. The issue is that including npm modules in your distribution zip means everyone who installs it has to download all those files and have them cluttering up their Foundry data folder.
M
mfi157d ago
I've had some files that refused to be imported when referenced, even when within the modules folder. I was following the same export pattern, haven't been able to deduce why it was occurring. Browserify was just the easiest thing to instanty use without any config. I haven't worked with Vita but might take a look.
Want results from more Discord servers?
Add your server
More Posts
(Paid) System Dev AssistanceHello, I am developing a new game and would like to build my own game system in foundry vtt. I'm nothow to handle items and effects?I've been working on a system for a game that needs a concept that seems like it might be a good fitAdvice on the general programming model a system should followI'm brand new to foundry dev and I want to make sure I am gaining the correct understanding of the eAdvice for compendium data in a custom systemHello, i'm new here! I was wondering if I could get a little direction for storing data about my gaDialog Box Auto-Closing Upon Opening 2nd TimeI've been appending custom functionality to the simple worldbuilding system. At this time, I'm tryinActor collisionImplementing the homebrew knockback feature. It's almost working but how do I test if two actor tokeActor attributes update on player's sideI can't fathom how to make changes to actor attributes on player's side. According to documentation Sort itemsHello, I am searching for where is stored the data about "items" order, as I would like to order thNewby accepting advice on the Foundry API and Module DevelopmentHeya,im very new to Module development for foundry and im suuuuper rusty in the codding department bHow do I create/modify embedded document types?Let's say I want Items to also have Items embeddedHow do I specify an Array in my template.json?I want schema checking for elements inside of an undefined-length array in my template.json, how do Is is possible to create/change Foundry's document types?For instance, removing "Actor" and "Item" and adding new ones.ERROR: actors is not a valid embedded Document within the Token DocumentHi guys! New here, just purchased the software. Could we get any help on this elusive error? It's wHow to trigger "hotbarDrop" with element that are not "Item" ?Hello, I would like to know if it is possible to trigger "hotbarDrop" with element that are not "ItIs there a starter system based on the v10 DataModel?I'm creating a new system (sci-fi with a cyberpunk theme, battles in space, land vehicles, and closeNewb looking for advice on creating Compendium via codeI am new to Foundry and trying to figure out if it will be a good fit for my game. I have a fair amoAm I approaching character data updates incorrectly?In my system I've constructed a `core` and `modules` directory where `core` handles all of the critiLimit portions of character sheet to Owner/GM onlyHey friends, I'm new so if this isn't the best way to go about asking about system development questBeginners help with doorsHi foks. Apologies if i've posted this in the wrong place. I am totally new to working with Foundry,Blind chat message is public instead since v11I've updated to v11 today from v10.303 and now my blind chat messages aren't working anymore and I c