I started using electron.
In the index.html of electron-quick-start a JavaScript file is included using require()
.
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
Now I defined a simple function named flash()
in renderer.js
, as well as a log output:
function flash(text) {
alert("Text: " + text + "!");
}
console.log("Renderer loaded.");
After starting the electron app, I the the log-output in the console of the dev-tools. but calling flash()
does not work.
When including the script using
<script src='./renderer.js'></script>
I can call the function.
- Where does the
require()
function come from? - Why can't I use the function when including the file using
require
? - How can I use function defined in files that are required?
- When should I use
require()
and when should I usesrc=""
?