Using and Managing Inline JS
Using JavaScript in a Core Studio project provides many benefits. Much is typically placed as an 'Inline.js' option. The editor for inline is simple, and use of advanced editors like Sublime or Notepad++ are much more efficient...but cut/paste back and forth in not ideal.
Implementing EXTERNAL method JS is a plus, but a bit more work/knowledge is req'd.
A better way: INLINE JS using REQUIRE:
There is a simple solution that allows you to place STANDARD JS script into an externally located JS file, and REFERECE it in the INLINE JS body...and the EXTERNAL is 'pulled in' during publish, and running as if STANDARD JS.
In this sample project, I have two EXTERNAL JS files:
- One file "vpxConfig.js" holds IP and other related site data.
- Another file "vpx.js" hold all the JS function's for the VPX code routines.
The inline JS Script to call the vpx.js:
The blow 3 lines are used to execute the 'require' function. Substitute your js file name as needed.
var fs = require("fs");
var code = fs.readFileSync(_resolveLocalPath("vpx.js"), "utf8");
eval(code)
Now Run and Test:
Editing your JS File:
You can right-click on the JS file, and associate an external editor of your choice. Then you simple double-click the js file, and it will open in the editor.