Utilizing Vue.js in Combination with Nunjucks

In my organization, we have a build system in place for static websites that utilizes nunjucks for HTML rendering. I am interested in implementing Vue.js for prototyping purposes but do not want to mix it with nunjucks in my templates. Specifically, I am looking to integrate Vue.js into an index.njk page. Although the command to serve the pages is successful and builds without errors, I am encountering a problem where there is no output from Vue.

Within the Index.njk file, the structure looks like this:

{% block content %}
<main class="wrapper">
    <div class="prod-switcher">
        <prod-tabs></prod-tabs>
    </div>
</main>
{% endblock %}

I have designated .prod-switcher as the el for Vue. Our build system relies on Express for the server and uses webpack middleware for hot module reloading. The following snippet can be found in the server.js file:

files.forEach(fileName => {
            app.get(`/${fileName.replace('njk', 'html')}`, function(req, res) {
                const data = getDataFile(fileName);
                return res.render(fileName, data);
            });
        });

This code snippet's purpose is to locate all the njk files and render them, but nothing is actually being written to the file system. Upon inspecting the page in the browser, the .prod-switcher element seems to have disappeared, only to reveal the following unexpected content:

<main class="wrapper">
    <!--function (a, b, c, d) { return createElement(vm, a, b, c, d, true); }-->
</main>

We are utilizing Vue-loader within webpack. If anyone has insights or suggestions on whether achieving my intended setup is feasible, your input would be greatly appreciated.

Answer №1

After some investigation, it became clear that webpack was linking to a Vue runtime version. By including an alias property and pointing it to vue.esm.js, the issue was resolved.

resolve: {
    alias: {
        'vue$': 'vue/dist/vue.esm.js',
    }
}

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

Guide to displaying Django data on a Chart.js visualization

Feeling absolutely frustrated, I've been struggling with implementing chart.js on my Django website. All I want to do is plot two fields: Dates and Scores. Dates are in the format of `1/6/2022`, while scores are floats. The problem arises when passing ...

What is the reason I do not need to decode or parse a JSON string created by PHP in JavaScript?

When setting variables in a JS script, one way to do it is by wrapping them in JSON like this: <?php // Variables for JS $vars = array( 'fetchPath' => "$home/my-url.php", ); ?> <script> var phpVars = <?php echo json_encode( ...

Tips for avoiding the use of setTimeout in the mounted() hook to wait for props to become available in Vue

It seems like I have fallen into a routine of relying on setTimeout frequently to ensure that the initial data is loaded and accessible in my Vue components. There are times when I try to access this initial data only to find it not ready yet. Here's ...

Config service injection resulted in an undefined configuration

I have been working on resolving an issue that I previously posted about. Despite not fixing it yet, I have made some discoveries that might help someone assist me. Here is the setup in detail: app-config.json (/src/assets/): { "apiUrl": &qu ...

Utilizing jQuery to Trigger a Click Event on an Element Without a Class

What is the best way to ensure that the "click" event will only be triggered by an href element unless it does not have the "disablelink" class? Avoid processing the following: <a class="iconGear download disablelink" href="#">Download</a> P ...

Working on executing various methods with a JavaScript client on a Flask RESTful API that requires authentication

I'm currently developing a JavaScript client-side app to interact with a Flask RESTful API. I've implemented some methods that require user authentication, but for some reason, even after logging into the server, I receive a 401 error (Unauthoriz ...

What causes certain webpages to experience delays? (Advertisement impact)

Whenever I visit low-quality websites filled with ads, I often experience a delay where part of the site loads and then stalls for seconds before loading the rest. However, when I use AdBlock, the site loads much faster. What exactly is causing this stal ...

I'm looking to fetch my post request with JavaScript - does anyone know how to

In my current setup, I have two main projects. The first project involves using Node.JS for handling data transfer tasks. jsonobj = JSON.stringify(generateMockData) xhrToSoftware.send(jsonobj); xhrToAPI.open("POST", "http://127.0.0.1:8000/pa ...

Fixing the Angular2 glitch: 'Uncaught TypeError: Cannot read property 'apply' of undefined'

Seeking solutions: How can I fix the "Uncaught TypeError: Cannot read property 'apply' of undefined" error that keeps showing up in the console of my Angular2 application? Any helpful insights are appreciated! ...

The issue of v-if not functioning as expected within a v-for loop when clicking a

I am working on displaying the correct template inside a v-for loop based on a v-if condition. When a button is clicked, it should change the value within the v-if statement. <div v-for="(items, index) in suppliers" :key="index"> <v-btn @click ...

Leverage a custom function within the browser.execute_script() method in Selenium using Python

I am attempting to incorporate a JavaScript code into the console using Selenium in Python, but I am unsure of how to proceed. Here is the function: function login(token) { setInterval(() => { document.body .appendChild(document.create ...

When dynamically creating content with .html(), the JavaScript styling does not get applied properly

As I work on creating a mobile website using Cordova, I've come across an interesting javascript framework called nativedroid2. This framework offers ready-made html classes and effects that can be applied to the code. Currently, my goal is to dynami ...

Leveraging AJAX to transmit a JavaScript variable to PHP within the same webpage

I have a webpage where I want to update a PHP variable based on the value of a name attribute when a user clicks on a link. Here is an example of what I am attempting to accomplish: // PHP <?php $jsVar = $_POST['jsVar']; echo $jsVar; ...

Encountering a TypeError while pre-rendering a page during the npm run build process

I am currently preloading this page on my Next.js application: const router = useRouter(); if (!router.isFallback && !postData?.slug) { return <p>Hmm... looks like an error</p> } const formatDate = date => { const newDa ...

What is the best approach to creating a Typescript library that offers maximal compatibility for a wide range

My Vision I am aiming to develop a versatile library that can cater to both JavaScript and TypeScript developers for frontend applications, excluding Node.js. This means allowing JavaScript developers to utilize the library as inline script using <scri ...

Navigating through Vue.js development environments using relative paths

I'm encountering difficulties with navigating paths between the development and production environments in a project involving Laravel and Vue.js. Regarding CSS files: In the development environment, using npm run hot requires absolute paths in URLs ...

What could be causing only certain parts of my JavaScript to function properly after switching between PHP cases?

I've hit a roadblock trying to understand why only certain parts of my JavaScript code are functioning properly. Currently, I'm utilizing a switch-case in my PHP files. It's interesting to note that both "content_allinboxes.php" and "conte ...

Problem with Loading OBJ Files in THREE.JS

I'm having difficulties with the OBJ Loader in THREE.JS. Here is the code I've written: //Setting up the scene scene = new THREE.Scene(); //Creating the camera camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, ...

Promise.all does not pause for a new Promise to finish resolving

This particular section belongs to a spa utilizing nodejs and jquery. The getToday function is supposed to console log "result:", leading to the entire output being 1, followed by result:, and finally 2. However, it seems that the code does not wait for ge ...

What is the best way to erase information displayed when hovering over an element using mouseout?

Whenever the user hovers over an image, an information box appears regarding that specific image. The information inside the box changes as I move over another image, but when not hovering over any images, the information box remains visible. Unfortunately ...