Tips for activating Vue.js production mode with webpack 2.7

I have encountered performance issues with Vue.js in my existing code base. Additionally, I noticed a notice in the browser console:

So, I believe that one simple solution could be to switch Vue into production mode.

Following the recommended link, I attempted to follow the webpack instructions. Our current version of Webpack is 2.7 (while the latest stable version is 4.20). The instructions mention that for Webpack 3 and earlier versions, you need to utilize DefinePlugin:

var webpack = require('webpack')
module.exports = {
  // ...
  plugins: [
    // ...
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('production')
    })
  ]
}

Therefore, I added a build script in my package.json file:

To generate a production build, I execute yarn run build, which triggers a build.js file (paste here) that calls both webpack.base.conf.js (paste here) and webpack.prod.conf.js (paste here).

In these paste files, I implemented the DefinePlugin as per the documentation's suggestion.

I also came across a file named vue-loader.conf.js (paste here), where I included the DefinePlugin as an extra precaution.

Even though I can successfully run yarn run build without any errors, when I serve the site through Apache and check the browser, it still displays a message indicating that we are in development mode.

To confirm whether it is using the files created by webpack, I deleted the folder /public/webpack/ entirely and observed that the web interface failed to load properly without those missing files. I then rebuilt the project to see if it loaded correctly after the process was complete. It does seem to use the files generated by the webpack process, but Vue is not being initialized in production mode.

What could be causing this issue?

Answer №1

It seems like the issue may lie within your 'webpack.base.conf.js', as I suspected. Thank you for sharing it. After some searching, I came across a solution to the problem of production not being detected on GitHub here

The fix involves changing 'vue$': 'vue/dist/vue' to 'vue$': vue/dist/vue.min in the production environment.

You can refer back to the original answer:

@ozee31 The alias 'vue$': 'vue/dist/vue' is causing the issue. Instead, use vue/dist/vue.min in the production environment.

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

Establishing a Connection with Node/Express Routing via JavaScript

When developing a web application using HTML, JavaScript, and Node.js with Express, I often find the need to navigate between pages based on user actions. In HTML, one approach is to add an href link and then set up routes in my app.js file to handle the ...

Unable to locate and interact with a specific element within a dropdown menu while utilizing Protractor

I am currently facing an issue with selecting a checkbox from a dropdown in jq widgets. The code seems to work fine when the element is visible on the screen, but fails otherwise. I have tried various methods such as executeScript and scrollIntoView to bri ...

Issues arise when trying to use Prettier and ESlint in conjunction with one another

It appears that prettier is not formatting the code as desired. Here is my current ESLint configuration: "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ &q ...

Swapping values in JSON by comparing specific keys: A guide

I have JSON data that contains a key called reportData with an array of values: {"reportData":[ ["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"], ["1186","R","5t","R","01","L","TP","00110","1854","2016" ...

Issue encountered during npm installation of jdbc

I encountered numerous challenges with certain dependencies and errors that I am unable to pinpoint the exact cause of. Could you please assist me by outlining the necessary steps that need to be taken? The error appears like this: C:\>npm insta ...

Switching up icons using React Spring - a step-by-step guide!

Is it possible to change the icon when I click on it using react spring? For example, if I click on " ...

The ajax success error function does not trigger in jQuery

Hey, check out my code below: <html> <head> <script src="http://code.jquery.com/jquery-1.8.0.min.js"> </script> </head> <body> <form id="foo"> <label for="bar">A bar</label> <input id ...

Is it possible to use Node.js child processes without carriage returns?

My Node.js script is set up to handle some database operations by creating child processes using the spawn functionality. However, I encountered a strange issue where the output stopped displaying carriage returns. Here's an example of what was happen ...

Vue component that does not render any UI elements but has a click listener功能

I recently came across a comprehensive article discussing the concept of renderless components, which can be found at: Essentially, a renderless component would have a structure similar to the following: export default { render() { return this.$sco ...

What is the best approach for presenting MySQL data on an HTML div through Node.js?

When working with Node.js, I prefer using Express as my framework. Here is the AJAX code I have on my member.ejs page: function load_member(){ $.ajax({ url: '/load_member', success: function(r){ console.lo ...

Automatically integrating Nivo Lightbox into your website

I incorporated Nivo Lightbox into my website, seamlessly integrating all images with the plugin using the following code: <div class="portfolio-item"> <div class="portfolio-thumb "> <a class="lightbox" data-lightbox-type="ajax" title="Strat ...

The component's div does not respond to the max-width attribute

I'm currently facing an issue with my chart component in a view. I've been trying to reduce its size using max-width property but it doesn't seem to be working. Below are the relevant code snippets: <div id="chart"> < ...

Utilizing an external JavaScript file for developing applications on Facebook

I am looking to incorporate external JavaScript into my Facebook application development. Specifically, I am hoping to utilize the Ajax tab feature in my application. ...

What is the best way to send data from ajax to a django view?

I have a script for ajax that retrieves the public key and sends other details to the Stripe server for payment. However, I am struggling with sending the dynamic value of the price to item_line. fetch("/config/") .then((result) => { return re ...

How to Handle Tab Navigation on a Mobile Website without Javascript?

My website primarily targets mobile devices, with tabs in the top navigation. Currently, these tabs are hard coded instead of utilizing Javascript. We want to ensure our site is accessible on all mobile devices, including those without Javascript support. ...

"Trouble With JSON and ASP.NET WebMethod: Server-Side Method Not Executing

I am attempting to send parameters to my code behind using the WebMethod. Although I am successfully reaching the end of ajax, the method in my aspx.cs code behind is not being called and I am encountering an error. Operation failed! Details: '[ob ...

Utilize Angular to Transfer HTTP Array Data from a Service to a Component

As I work on developing an app with Angular, my current challenge involves a service that retrieves an Array of Data from an online source. My goal is to make this array accessible in other components but I'm facing difficulty in passing the data to t ...

Issue: Certain dependencies have been imported but cannot be resolved, preventing us from utilizing the custom library developed with vue and vite

I recently developed a library that includes components, enums, and interfaces using vite and vue. Upon installing the library with npm install file:./dist/, it appeared in the nodemodule folder. However, when trying to import a specific component, I enc ...

Is there a way for me to display the output from Firebase on the html template when the page first loads?

I am currently in the process of building a blog post page using VueJs. Here is my template: <template> ... <q-item-section> <q-item-label class="text-subtitle1"> <strong>Danny Co ...

Error encountered while attempting to send SendGrid email to multiple recipients

Currently, I am using const sgMail = require('@sendgrid/mail'); with sendgrid version 7.6.2. Whenever I attempt to add two email addresses in an array and then pass it into either send() or sendMultiple(), an error is being thrown like below. st ...