简体   繁体   English

Vue.js 在现有应用程序上的电子

[英]Vue.js over electron on an existing application

I will try to explain my whole situation:我将尝试解释我的整个情况:

I wrote a CLI application in node.js that started growing, I started with a parser, after that I created a web API to interact with the parser, and finally I created a web app that, by consuming the API displays information.我在node.js中编写了一个开始增长的 CLI 应用程序,我从一个解析器开始,然后我创建了一个 Web API 来与解析器交互,最后我创建了一个 Web 应用程序,通过使用 API 显示信息。 This web app is heavily based on vue.js这个网络应用在很大程度上基于vue.js

I started working in putting all of this together using electron, so I installed the npm package electron for my parser, created the main and renderer scripts, updated the packages.json, added a plain HTML and it gave me the first window with the rendering.我开始使用电子将所有这些放在一起,所以我为我的解析器安装了 npm 包electron ,创建了主脚本和渲染器脚本,更新了packages.json,添加了一个普通的 HTML,它给了我第一个带有渲染的窗口.

At this point I started moving the code from my previous web project.在这一点上,我开始从我以前的 web 项目中移动代码。 I thought it would be easy to do this, just a few changes to the web code (it is very simple yet, mainly one silly js, one html, and the libraries (Bootstrap and vue.js)我认为这很容易做到,只需对网络代码进行一些更改(它非常简单,主要是一个愚蠢的 js、一个 html 和库(Bootstrap 和 vue.js)

Soon enough I realized that the npm vue package (vue-cli, electron-vue, etc) is (allegedly) the way to go for electron apps, as suggested in several resources, to mention:很快我意识到 npm vue 包(vue-cli、electron-vue 等)是(据称)电子应用程序的方式,正如一些资源中所建议的那样,提到:

The thing is that most of them start from the premise that you have nothing, and they use a boilerplate to create a skeleton of an empty Electron/Vue app.问题是他们中的大多数都是从你一无所有的前提开始的,他们使用样板来创建一个空的 Electron/Vue 应用程序的框架。 But my case is different, I have a backend ready, I have electron already plugged into this backend但是我的情况不同,我有一个后端准备好,我已经将电子插入这个后端

So... What's the question?所以……有什么问题吗?

The question is simple, what are the advantages and disadvantages of just using <script src="vue.js"></script> in an electron GUI instead of using the npm package?问题很简单,在电子 GUI 中仅使用<script src="vue.js"></script>而不是使用 npm 包的优缺点是什么? I was able to make the vue.js work like that, but as I have not seen a single resource doing this, I wonder if I will at some point get to further problems.我能够让 vue.js 像那样工作,但由于我没有看到任何资源这样做,我想知道我是否会在某个时候解决更多问题。 Specifically:具体来说:

  1. Should I go for the boilerplate and start plugging my previous code to that?我应该选择样板文件并开始插入我以前的代码吗?
  2. If I use the <script src=... approach, will the packaging be painful?如果我使用<script src=...方法,打包会很痛苦吗?
  3. Are there any benefits in using the npm vue (Remember I only use to render results that I have already parsed)使用 npm vue 有什么好处吗(记住我只用来渲染我已经解析过的结果)
  4. If you could point me to a resource that mentions this way is greatly appreciated.如果你能指出我提到这种方式的资源,我将不胜感激。

I would like to know what can (or definitely will) go wrong.我想知道什么可能(或肯定会)出错。

Thanks in advance!提前致谢!

Not 100% sure if I fully understand your questions, but I'll try to answer as best I can.不能 100% 确定我是否完全理解您的问题,但我会尽力回答。

1. Should I go for the boilerplate and start plugging my previous code to that? 1.我是否应该使用样板并开始插入我以前的代码?

Yes and no.是和否。 The biggest reason for going with this approach would be that by using a boilerplate it's much easier to get help with your project if you hit problems further down the line.采用这种方法的最大原因是,通过使用样板,如果您进一步遇到问题,则可以更容易地获得项目帮助。 Using your own solution means fewer people will even be able to understand what your problem is, and even fewer will be willing to set up a project of their own to recreate your issue to help you debug it.使用您自己的解决方案意味着更少的人甚至能够理解您的问题是什么,甚至更少的人愿意建立自己的项目来重现您的问题以帮助您调试它。

However, no you don't have to go with a boilerplate, boilerplates were made by people similar to yourself.但是,不,您不必使用样板,样板是由与您相似的人制作的。 You could probably put up your code somewhere and call it a boilerplate that other people will start using if they wanna make a vue and electron based project.你可以把你的代码放在某个地方,并称之为样板,如果其他人想要制作一个基于 vue 和电子的项目,他们就会开始使用。 If your project works with your approach and makes sense to you there's no reason why you'd need to conform to how other people do things.如果您的项目适用于您的方法并且对您有意义,那么您就没有理由需要遵循其他人的做事方式。

2. If I use the <script src=... approach, will the packaging be painful? 2.如果我使用<script src=...方式,打包会不会很痛苦?

(Edited after clarification) (澄清后编辑)

There are two basic ways of distributing a Vue app.分发 Vue 应用程序有两种基本方式。 Static or server side rendered.静态或服务器端呈现。 Static means you generate static html files and scripts that you can distribute to any web host on the market and it'll run just fine.静态意味着您生成静态 html 文件和脚本,您可以将它们分发到市场上的任何网络主机,并且它会运行得很好。 Server side rendered is basically your own little server, like an Apache web server, that compiles your files when a user requests your website.服务器端渲染基本上是你自己的小服务器,就像一个 Apache Web 服务器,它在用户请求你的网站时编译你的文件。

For a server side rendered application you're running and developing your code in a mix of Node.js code for your server/backend, and Ecmascript for your client side code which is compiled into plain javascript before being sent to the user.对于服务器端呈现的应用程序,您正在运行和开发您的代码,其中混合使用了用于服务器/后端的 Node.js 代码和用于客户端代码的 Ecmascript,该代码在发送给用户之前被编译为纯 javascript。 Before you write this off as not being an option for you I wanna mention that DigitalOcean lets you create "droplets" (virtual machines) that you can most definitely use for production grade purposes, so you can run your server in a droplet for $5 per month and just use a registrar to register your domain.在您认为这不是您的选择之前,我想提一下,DigitalOcean 允许您创建“液滴”(虚拟机),您绝对可以将其用于生产级目的,因此您可以以每个 5 美元的价格在液滴中运行您的服务器月,只需使用注册商注册您的域。 This is actually cheaper and gives you more power over your server, and in my experience is also more secure and better performing (partially because you can simply upgrade your droplet if it's not fast enough).这实际上更便宜,并为您提供更多的服务器能力,而且根据我的经验,它也更安全,性能更好(部分原因是如果速度不够快,您可以简单地升级您的 Droplet)。 It's also generally cheaper than a web hotel.它通常也比网络酒店便宜。

For a static website you basically have two options, with or without Webpack (with Webpack is far superior).对于静态网站,您基本上有两种选择,使用或不使用 Webpack(使用 Webpack 更胜一筹)。

Without Webpack you would, like you're doing, just include the <script= version of Vue and then develop your program purely in javascript.如果没有 Webpack,您会像现在一样,只包含<script=版本的 Vue,然后纯粹用 javascript 开发您的程序。 This is more tedious and in the long run results in worse performance and a bad workflow, though it does work to do.这更乏味,从长远来看会导致更差的性能和糟糕的工作流程,尽管它确实可行。

With Webpack you write your application in Ecmascript, where you would import Vue so that Webpack can compile all your scripts and .vue files into a single main.js file.使用 Webpack,您可以在 Ecmascript 中编写您的应用程序,您可以在其中import Vue,以便 Webpack 可以将您的所有脚本和.vue文件编译到一个main.js文件中。 By importing Vue and all your components Webpack can make sure you're only ever running code that actually needs to be run, so you'll experience a potentially massive performance boost.通过导入 Vue 和所有组件,Webpack 可以确保您只运行实际需要运行的代码,因此您将体验到潜在的巨大性能提升。

Are there any problems with packaging?包装有问题吗? No, as long as all you need is the main vue.js file, but as your project gets larger and needs more and more Vue components and plugins from elsewhere you're gonna end up with a lot of script= tags cluttering your website.不,只要您需要的只是主要的 vue.js 文件,但是随着您的项目变得越来越大并且需要越来越多的来自其他地方的 Vue 组件和插件,您最终会在您的网站上出现大量script=标签。 It works, it's just that it's way easier to simply only have a script="main.js" tag and then let Webpack generate main.js for you.它有效,只是简单地只有一个script="main.js"标签然后让main.js为您生成main.js更容易。

Take a look at a basic Webpack+Vue project.看一个基本的 Webpack+Vue 项目。 It'll give you a better idea of how a Webpack project works.它会让你更好地了解 Webpack 项目的工作原理。

  1. Install vue-cli : npm install -g vue-cli安装vue-cli : npm install -g vue-cli
  2. Create a simple project: vue init webpack-simple my-project创建一个简单的项目: vue init webpack-simple my-project

3. Are there any benefits in using the npm vue (Remember I only use to render results that I have already parsed) 3.使用npm vue有什么好处吗(记住我只用来渲染我已经解析过的结果)

(Edited after clarification) (澄清后编辑)

Apart from the above mentioned?除了上面提到的? No. It's more related to whether or not you're willing to use Webpack or not, and if you're ever gonna need more components/plugins for Vue developed by other people.不。这与您是否愿意使用 Webpack 以及您是否需要更多由其他人开发的 Vue 组件/插件有关。

Performance differences on loading only Vue with script= vs require ?使用script=require加载 Vue 时的性能差异? Negligible.微不足道。

Performance differences on loading more Vue components and plugins?加载更多 Vue 组件和插件的性能差异? Noticeable, more and more based on the size of your project.值得注意的是,越来越多的基于您的项目的大小。 Require loads when it's needed, script loads regardless.在需要时需要加载,无论如何加载脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM