0

I'd like to add on-the-fly parsing capabilities to the Node-RED function node using Uglify-JS. I'm in the file "80-function.html", but for some reason, I can't get a reference to UglifyJS. I'm trying to instantiate it by simply calling

var UglifyJS = require('uglify-js');

...but it returns null. I've made sure that it is installed under /usr/lib/node_modules/node-red/node_modules/uglify-js/

Where should the instantiation of UglifyJS go? I can't find any examples of "require" being used in the html part of the nodes. My code structure is below:

RED.nodes.registerType('function',{
 ...
 oneditprepare: function() {
  ...
  var currentEditor = this.editor;
  this.editor.on("change", function(e) {
       var currentScript = currentEditor.getValue();
       //this is where I'd like to parse my script using Uglify

Thanks!

1 Answer 1

1

require() is how you include libraries on the NodeJS side, not the HTML side.

Are you sure uglifyjs can be used in the browser? Before trying to add it to Node-RED check you can load it into a normal web page using the <script> tag.

Once you have that working then you can look at having the node load file dynamically when the node edit dialog is opened. An example of how to do this can be found in the geofence node.

Also you probably discuss what you are trying to achieve here either on the Slack Team or the Mailing list (both are linked to from the Node-RED homepage) to decide if any changes you plan to make to the function node will be accepted by the project.

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

1 Comment

Ah thanks! It's more of a proof-of-concept, rather than something I'm going to push to node-red's git. I'll take a look at how geofence does this.

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.