How do you import libraries to a macro?
EmEditor can import certain JavaScript libraries to macros if you are using the new V8 engine on EmEditor v22.1.0 or greater. Most browser-compatible libraries can be used in V8. See the “limitations” section for compatibility information.
After you found a browser-compatible library, follow these steps to import it into a macro.
- Download the minified
.js
file of the library.- A non-minified file may not work if it imports another file.
- As an example, to use the datetime library Luxon, download the minified file under Basic Browser Setup.
- Open EmEditor. Switch to the v8 engine by going to Macros | Customize… and checking Use V8 as JavaScript engine.
- Create a new
.jsee
file. On the top of the file, write#include "library.js"
, replacinglibrary.js
with the relative or absolute path to the downloaded JS file.- Don’t forget to escape backslashes.
"C:\\folder\\folder"
- If
luxon.min.js
was downloaded to the same folder, include it with#include "luxon.min.js"
.
- Don’t forget to escape backslashes.
To test if Luxon was imported correctly, we can run the following macro which prints the current time.
#include "luxon.min.js" alert(luxon.DateTime.now().toISO());
Limitations
- Node APIs and
npm
cannot be accessed in V8. - Certain Web APIs, such as
import
,fetch
, and DOM manipulation are unavailable in V8.