electron-userland / electron-forge-templates

Templates bundled with Electron Forge <= 5 to create Electron apps using popular JavaScript frameworks
107 stars 23 forks source link

With Vue + Vue-Router, Can't use lazyload component #46

Closed chenzhiguo closed 7 years ago

chenzhiguo commented 7 years ago

The project is created by electron-forge init demo --template=vue Only vue + vue-router, I use the many method to lazyload vue component, but has error:

Error: Failed to resolve async component default: AssertionError: path must be a string
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1708:17
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1766:15
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1717:11
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1742:66
    at Array.map (native)
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1742:38
    at Array.map (native)
    at flatMapComponents (/Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1741:26)
    at /Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1677:5
    at iterator (/Users/Silence/Desktop/electron-demo/demo/node_modules/_vue-router@2.7.0@vue-router/dist/vue-router.js:1876:7)

**1. Lazy load must rely on webpack? Has the electron-forge include it?

  1. I am trying many way, but there is no way to work properly. such as:**
    
    'use strict';
    import Vue from 'vue/dist/vue.js';
    import Router from 'vue-router/dist/vue-router.js';

Vue.use(Router);

let router = new Router({ routes: [ { path: '/', redirect: '/index' }, { name: 'login', path: '/login', // component: require('./components/Login.vue') //working // component: resolve => System.import('./components/Login.vue') //not working // component: () => import('./components/Login.vue') //not working component: view('Login') //not working }, { name: 'test', path: '/test/:userId', component: resolve => require(['./components/Test.vue'], resolve) //not working }, { path: '*', redirect: '/' } ] });

/**

export default router;


Can your help me point out the mistake? Thanks! waiting...
MarshallOfSound commented 7 years ago

Uhhh, System.import is like not a thing in Electron? Why can'y you just either use require which you indicate works or use import Thing from './here'; at the top of the file?

chenzhiguo commented 7 years ago

@MarshallOfSound Just to lazyload the *.vue file. If use require or import, will the file be loaded immediately?

MarshallOfSound commented 7 years ago

@chenzhiguo Why do you want to lazy load it though? You aren't loading the component over HTTP, there is no file size concern here. It's literally just reading a file from the local filesystem. Lazy loading for Electron apps makes no sense?

chenzhiguo commented 7 years ago

Aha...I feel you are very reasonable, you are convinced. But, if I want use it, Is required to use webpack? Do you know this one? @MarshallOfSound

MarshallOfSound commented 7 years ago

@chenzhiguo If you realllllyyyy want to lazy load even if you're literally just loading a local file 😕

You can just wrap require in a function so it isn't called immediately.

  component: () => require('./components/Login.vue')
wahengchang commented 5 years ago

YOU guys are so funny ! lol (commented by a guy who is looking for solution of vue-router in eletron)