railsware / bozon

🛠 Command line tool for building, testing and publishing modern Electron applications
MIT License
758 stars 52 forks source link

bozon + three.js #44

Closed ghost closed 7 years ago

ghost commented 7 years ago

hi, tried running threejs inside a bozon project template used sample from https://github.com/jeromeetienne/electron-threejs-example example running on electron boilerplate (just drag and drop.

i tried to change code to bozon , this is what I edited:

`var electron, path, json;
let window;
path = require('path');
json = require('../../package.json');

electron = require('electron');

electron.app.on('ready', function() {

  window = new electron.BrowserWindow({
    title: json.name,
    width: json.settings.width,
    height: json.settings.height,
    frame: false,
    transparent: true

  });

  window.loadURL('file://' + path.join(__dirname, '..', '..') + '/index.html');

  window.on('closed', function() {
    window = null;
  });

});
`

and this example code:

`const {app, BrowserWindow} = require('electron');

let mainWindow;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  if (process.platform != 'darwin')
    app.quit();
});

// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
  // Create the browser window.
  mainWindow = new BrowserWindow({
          width: 800, 
          height: 600, 
          frame:false, 
          transparent: true
  });

  mainWindow.setIgnoreMouseEvents(true)

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/index.html');

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});
`

but on runnig bozon start nothing happens... this is the index.html

`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <link rel="stylesheet" href="stylesheets/application.css" />
  <script src="javascripts/renderer/application.js" type="text/javascript"></script>
</head>

<body>
<div id="container"></div>

</body>
<script src="javascripts/three.min.js"></script>
<script>
...here code of the example</script>
`
alchaplinsky commented 7 years ago

@alko79 Which OS are you running that on?

ghost commented 7 years ago

@alchaplinsky windows 10 i checked on developers tool for errors, (sorry for not posting before also i moved threejs in folder vendor)

Failed to load file:///C:/3dview/builds/development/vendor/three.min.js
 resource: net::ERR_FILE_NOT_FOUND

if i copy manually the three.min.js in builds and run reload it works. but why calling

is working and calling is not working? shouldn't bozon find any js in the path? sorry if this is a stupid way of asking surely there is a valid reason for that but I cannot figure it
ghost commented 7 years ago

alternatively can be used a custom task to add loading from vendor folder for "third party" js?

bozon.task('scripts:main', function () {
  return bozon.src('javascripts/main/**/*.*').pipe(bozon.dest('javascripts/main'))
})
bozon.task('prepare:app', bozon.hooks, function () {
  var settings = new bozon.Settings()
  fs.stat(bozon.sourcePath('node_modules'), function (err, stat) {
    if (!err) {
      var command = settings.platform() === 'windows' ? 'copy' : 'cp'
      bozon.spawnSync(command, [
        '-r',
        bozon.sourcePath('node_modules'),
        bozon.destinationPath()
      ])
    }
  })
ghost commented 7 years ago

ok that did the trick on win10 but now i have problem with electron builder:

Error: Exit code: ENOENT. spawn node-gyp.cmd ENOENT
    at C:\3dview\node_modules\electron-builder-util\src\util.ts:75:16

on building i added a task on gulpfile:

bozon.task('scripts:vendor', function () {
  return bozon.src('vendor/**/*.*').pipe(bozon.dest('vendor/'))
})

now electron start works loading the local threejs.min

on packing i got that error, dont know if at this point error is on bozon side or on electron builder since i found a lot pages about node-gyp and windows.

ghost commented 7 years ago

ok it was on electron builder side, i reinstalled all required files for win10 using all 64 bit versions(node, python windwos build tools visual c++ ect) and it worked also on packing the installer in the end you were right, that was win10 not "friendly" to node/electron