Harnessing the power of Vue.js within an Nw.js project, sans bundlers: Unveiled

I am currently developing a software application using NW.js and Vue.js.

I have decided to build the application without reliance on compilers or bundlers.

Although I have successfully installed the Vue.js library via npm, I am facing an issue where it is not rendering properly when trying to utilize it through require. Even though I can see console logs from the created and mounted callbacks, the webpage remains blank with an empty <div id="app"></div>.

Here is a snippet of my code:

  • index.html (the entry point of the nw.js app):
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
</head>
  <body>
    <div id="app">ww</div>
    <script src="/src/app.js"></script>
  </body>
</html>
  • app.js file:
// const Vue = require('vue/dist/vue.common.dev.js');
// const Vue = require('vue/dist/vue.common.prod.js');
// const Vue = require('vue/dist/vue.common.js');
// const Vue = require('vue');
const Vue = require('vue/dist/vue.js');

const hello = Vue.component('hello', {
  data () {
    return {
      hi: 'Well, hello there!'
    }
  },
  template: '<div>uu {{ hi }}</div>',
  created () {
    console.log('Created!');
  },
  mounted () {
    console.log('Mounted!');
  }
});

new Vue({
  el: '#app',
  components: { hello },
  render : h => h(hello),
});

Despite attempting different sources for Vue.js in the code above, none seem to resolve the rendering issue - even though both console logs are present. The only successful workaround I found was by utilizing the Vue.js source from a CDN in the index.html file (as shown in the commented out section).

Is there a way to achieve the same result by loading the file locally through require() from node_modules? Alternatively, I can download the Vue.js file contents from the CDN and load it that way, but I would prefer to stick to an npm-based approach.

Answer №1

When utilizing Vue CDN, it's designed to function smoothly without the need for bundlers. However, if you opt for the npm version, bundlers are necessary for internal operations. Additionally, consider incorporating node integrations settings in nw.js.

Although, I recommend utilizing bundlers as they can enhance your build size optimization. You may also explore using the nw plugin offered by vue-cli.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm receiving the error message "Fatal error: Call to a member function query() on a non-object," what could be causing this issue?

Need help with fixing an error on my private server realmeye. The error message I'm receiving is: Fatal error: Call to a member function query() on a non-object in /home/noxus/public_html/realmeye/index.php on line 112 =========================== ...

Implementing Next.js with Firebase's onAuthStateChanged method allows seamless user

const checkUserAuth = () => { const [user, setUser] = useState(''); useEffect(() => { auth.onAuthStateChanged(function handleAuth(user) { if (user) { setUser(user); } else { setUser(null); } }) ...

React: When state is updated and a console.log is used, the console displays the previous state instead of the updated

Upon clicking the button, a peculiar sequence unfolds - the console displays 0 and the page refreshes to show 1 function App() { const [count, setCount] = useState(0); const addOne = () => { setCount(count + 1) console.log(count) } ...

Is there a way to modify the type attribute from submit to button in vue.js 2?

My attempt at solving this issue is as follows: <template> <button @click="checkout" class="btn btn-danger pull-right" :type="buttonType"> Checkout </button> </template> <script> export default { ...

JavaScript Event Listener causing the Sticky Position to Break

I am currently dealing with a situation where I want to create a slide-in side menu that remains sticky. However, when I apply the position: sticky CSS property to my menu container, it causes the entire menu to be displayed (instead of being pushed off th ...

What is the process of implementing a service in AngularJS?

For my Angular JS project, I am working on creating a module to include my service (file: utils/productos.js) and then load it as a dependency for my ventas module (ventas/ventas.js). However, I encountered the following error: Error: [$injector:nomod] Mo ...

How can I manually include a triangle in BufferGeometry using Three.js?

Recently, I've been exploring the quickest method to change a mesh's vertices using three.js. Through my experimentation, I discovered that modifying parts of mesh.geometry.attributes.position.array and then setting mesh.geometry.attributes.posit ...

Executing a npm script (script.js) with custom arguments - a step-by-step guide

I'm considering creating a setup similar to lodash custom builds. Basically, I want to allow users to input a command like: lodash category=collection,function This would create a custom module with the specified category. I've been looking in ...

Server-side form validation in Node.js with client-side feedback handling

Express-form is a validation plugin for node.js/express that offers powerful features. However, the examples and documentation currently only show server-side responses (console.log), which may not be very user-friendly. Two possible solutions come to min ...

Are there any JavaScript charting tools that can draw in a clockwise direction with multiple data points?

Can anyone recommend a JavaScript live chart/graph library that can create clockwise graphs with multiple points, similar to the example below? https://i.sstatic.net/dQfK4.png ...

Getting the string value from a table row using JavaScript

I need to capture the value of result_status from the row labeled status. If all values in the row labeled status are 'pass', then the result_status will also be 'pass'. However, if any one of the values in the row labeled status is &a ...

Learn the steps for generating an array of objects in AngularJS or JavaScript

I have an array named $scope.data2 and I am looking to create another array of arrays based on the data provided below: $scope.data2 = [ {"dt":"07 Jul 2015","avgdelay":"10","code_sent_time":"07 Jul 2015 12:30 PM" ...

Rotating through elements in timed intervals

After exploring various examples of how to show/hide divs with a JavaScript timeout, I am still unable to resolve my specific issue. I currently have six divs that I want to cycle through sequentially every 10 seconds, starting with div #one. Although my ...

What is the best method to update values from a JSON file that has been read?

Trying my hand at modifying values in a JSON file without changing one particular value. Below is the code I've come up with, but to provide more context, I'll add some filler text so you can skim through and analyze the code. Don't be too h ...

Controlling user login sessions and cookies with angular.js is essential for ensuring secure and seamless

I have a login application where I need to implement session and cookies using angular.js. Below is the code for my login functionality. loginController.js: var loginAdmin=angular.module('Channabasavashwara'); loginAdmin.controller('log ...

Pausing and then resuming an interval function within the same function

I'm struggling with an $interval function that runs every second. The function retrieves user credentials from local storage and checks if they have expired. If they have, it refreshes them with new ones. Otherwise, it does nothing. This is what my ...

Difficulties with managing button events in a Vue project

Just getting started with Vue and I'm trying to set up a simple callback function for button clicks. The callback is working, but the name of the button that was clicked keeps showing as "undefined." Here's my HTML code: <button class="w ...

Node.js and MySQL: Troubles with closing connections - Dealing with asynchronous complexities

I am currently working on a Node program to populate my MySQL database with data from files stored on disk. While the method I'm using seems to be effective, I am facing challenges in ensuring that asynchronous functions complete before ending the con ...

What is the reason behind the necessity of adding an extra slash when reloading the page and controller in AngularJS by using $location.path()?

In AngularJS, when you use $location.path() and pass the same URL as the current one, it does not reload the page and controller. However, if you add an extra slash at the end of the URL like this: $location.path('/currentURL/'); it forces a re ...

Mastering MongoDB update functions in JavaScript

I've encountered some difficulties while using the MongoDB API to update a document. Despite trying various methods, none of them have been successful so far. Strangely enough, inserting and deleting documents work perfectly fine. Let me explain what ...