NodeJS - Having trouble reloading external js? - node.js

I am trying to build a sort of plugin manager that can reload external source files on the fly without actually shutting down the node app. Just as a quick proof of concept is just eval'd my plugin files that simply are just functions being prototyped to a class. Everything seemed to work great, except that I cant seem to get the scoping right. The functions get evaluated and prototyped, but im not sure why the functions cant grab global vars. Does anyone have any advice on this?

Rather than manually loading the file, you could just rely on require.
Now, the only problem is that require has an internal cache and will only load modules once. However, you can force it to unload with this quick workaround:
delete require.cache[require.resolve(myPlugin)];
require(myPlugin);

Related

Detect if code using NodeJS specific global objects, what may not exist in browser

My code was written in in NodeJS, but It can also work in browser. But I made mistake earlier when I tried read process.versions variable directly.
Is there way write test in NodeJS and test am I using some node specific global objects or variables ?
Test has to fail since process variable is not defined in browser. But when I did search, Google gives me tutorials "How run my tests in browser", but I am not fan of that idea, I would love to stay in NodeJS. I think maybe some wrapper what hides those node specific global variables. Most likely someone has dome something like that, but google wasn't big help.
I am using mocha for testing, but I am open for suggestions.

How to know what to use for fabricjs custom build

Since fabric js doesn't support tree-shaking via es6 modules for bundle size reduction i tried to do a custom build of fabricjs via website (http://fabricjs.com/build/) and via command line build and can't figure out which modules I need as I keep getting errors. I use
node build.js modules=text,circle,image,rect,line,image_filters
since to my understanding I dont use anything else. Then I got an error that sort of indicated I would need to import animation module too - even though I don't use animations from my pov. I did that an indeed the error disappeared and now I get this.drawSelectionBackground is not a function and have no clue to which package it belongs so I wonder hot to figure that out - or do I really have to just go for trial and error?
Figured it out it's the interaction module that I need to import even though I dont use interactions...
Pretty weird...

Run-time bundling of ES6 modules in ASP.NET MVC

Are there any existing solutions for run-time bundling of ES6 modules?
I'm looking to simplify JavaScript code development in a MVC5 web app. We're having issues with large, unwieldy JS files, so I'm hoping to get a module loader system in place. So far, I'm not finding any existing bundle transformers for ES6 or another module loader format. I'd be fine with using TypeScript or nodejs require style. I prefer not to use require.js style, though.
Perhaps there's a good reason this solution doesn't exist already. Maybe the dependency resolution processing is too much for a run-time bundling solution. But, I figure it's worth a shot to ask.
Solutions Considered
Prebuilt Web Client
Ultimately, this is where I want to be, but I need a stop-gap solution for now. I know how to put together a build system for an HTML client using grunt/gulp/webpack. But I don't want to have to tell developers to run webpack -w or something similar during development. Nor do I want to tell them to rebuild a solution for every JS change. They should be able to modify the file, refresh the browser, and see the change.
Directory Structure
This is the route I'll probably end up going with. Basically, this JS codebase consists of jQuery widgets and plain JS (helpers/common functions). So, if I structure the code in this directory structure and include the js dir, it should get me most of the way there:
js (DIR)
app-start.js
helpers (DIR)
widgets (DIR)
Widgets should be fine. Helpers, I can see issues where one function/class depends on another. Though, since a function call should never start with a helper (only a widget), this should work fine, assuming no globals are used (or maybe one global like 'App').

Update templates without restarting the app in CppCms

In this tutorial, it says:
Dynamic linking is a little bit more tricky, but it is much more
powerful as it allows you to load skins without relinking the
application. You can even update your application without needing to
restart it.
So I decided to put it to the test, and while the app was running, I replaced libmy_skin.so file with another skin.
The skin in the running app did not change.
Is the statement above incorrect, or did I do something wrong?
You need to turn this option on:
http://cppcms.com/wikipp/en/page/cppcms_1x_config#views.auto_reload

Get a JSON response and save to file using require.js

Im trying to make a plugin for require.js that allows me to call an external api, convert the json response and save it to a file.
Problems:
Im not sure if I am writing the plugin correctly
I cant seem to use node filesystem - though i am using r.js
I am hoping to do this on build, so that the file is ready before concat method happens (putting all files into one)
Is this even possible? Should I use a grunt task instead?
Any pointers or examples or tutorials or anything would be really useful.
In the end I used, https://npmjs.org/package/grunt-curl.
Was alot easier, and just modified the file a bit to wrap the response in define();
It allows the files to be downloaded on build and required later in the app

Resources