max-mapper / elementary-electron

NodeSchool workshop for learning Electron
228 stars 44 forks source link

index.js reference in index.html #22

Open marekpetak opened 8 years ago

marekpetak commented 8 years ago

Hi,

I'm sort of new to node and getting through this excersise I've seen file index.js being referenced in index.html. index.js is using node's require function. how does this reference work through html. you don't use require.js either...

ikbalsingh commented 7 years ago

The syntax "require(some_module)" is a javascript syntax not Node.js's syntax. and you can write javascript between tags and i hope this solves your problem

AntGol commented 1 year ago

To solves problem:

in index.html delete all tags. in app.js add index.js as prelod and add nodeIntegration option:

    var electron = require('electron')
    var path = require('path')
     electron.app.on('ready', function () {
       var mainWindow = new electron.BrowserWindow({width: 600, height: 800, webPreferences: {
      preload: path.join(__dirname, 'index.js'),
      nodeIntegration: true
    }})
       mainWindow.loadURL('file://' + __dirname + '/index.html')
     })

in index.js wrap code in event:

window.addEventListener('DOMContentLoaded', () => {
    require(some module)
})