Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External/secondary screen with a different Vue template #51

Closed
jsgv opened this issue Jan 3, 2017 · 2 comments
Closed

External/secondary screen with a different Vue template #51

jsgv opened this issue Jan 3, 2017 · 2 comments

Comments

@jsgv
Copy link

jsgv commented Jan 3, 2017

I am trying to create a second Window with a different html file than main.html. I am successfully creating the window and using the new external.html template, but am unsure about how to use its own vue template.

Folder structure

app/
  assets/
  components/
  App.vue
  background.js
  external.html
  External.vue
  main.html
  main.js
  package.json

background.js

import { app, BrowserWindow } from 'electron'
import path from 'path'

let mainWindow
let externalWindow

app.on('ready', () => {
  createMainWindow()
  createExternalWindow()
})

app.on('window-all-closed', () => {
  app.quit()
})

function createMainWindow () {
  mainWindow = new BrowserWindow({
    width: 600,
    height: 800,
    x: 0,
    y: 600,
    center: false
  })

  const mainURL = process.env.HOT
    ? `http://localhost:${process.env.PORT}/main.html`
    : 'file://' + path.join(__dirname, 'main.html')

  mainWindow.loadURL(mainURL)

  if (process.env.NODE_ENV !== 'production') {
    mainWindow.openDevTools({mode: 'bottom'})
  }

  mainWindow.on('closed', () => {
    mainWindow = null
  })
}

function createExternalWindow () {
  externalWindow = new BrowserWindow({
    width: 600,
    height: 800,
    y: 0,
    x: 680,
    center: false
  })

  const externalURL = process.env.HOT
    ? `http://localhost:${process.env.PORT}/external.html`
    : 'file://' + path.join(__dirname, 'external.html')

  externalWindow.loadURL(externalURL)

  if (process.env.NODE_ENV !== 'production') {
    externalWindow.openDevTools({mode: 'bottom'})
  }

  externalWindow.on('closed', () => {
    externalWindow = null
  })
}

Secondary window is loading external.html file correctly, but I'm unsure of how to have it load the External.vue file.

The secondary window is looking for the #app element.

[Vue warn]: Cannot find element: #app

main.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App'

Vue.use(VueRouter)

const router = new VueRouter({
  hashbang: false,
  abstract: true
})

router.map({
  '/': {
    name: 'home',
    component: Vue.component('home', require('./components/Home'))
  }
})

router.start(App, '#app')
@bradstewart
Copy link
Owner

In short, you need to generate a separate webpack bundle and HTML file for each window. This is kind of clunky and involves a lot of duplication with the current setup.

Try something like this:

  • Create an external.js file next to main.js
    • Should basically be a copy of main.js, but referencing External.vue instead of Home.vue.
  • Add a second external entry point to the webpack.dev-main.conf
  • Add a second HtmlWebpackPlugin to generate external.html to the webpack.dev-main.conf
    • Be sure to exclude the app bundle from external.html and vise versa.
  • Do the same thing in webpack.prod.conf (yea, I'm sorry...)

@jsgv
Copy link
Author

jsgv commented Jan 5, 2017

It worked. Thank you!

@jsgv jsgv closed this as completed Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants