Comparison of Vue CLI 3 vue.config.js and webpack.config.js in terms of handling plugins

Currently in my Vue CLI 3 setup, I'm encountering an issue with implementing the Terser Webpack Plugin to remove console.log and comments from the code. Despite following the production workflow below:

  1. Execute npm run build
  2. Run serve -s dist

vue.config.js:

module.exports = {
  publicPath: "./"
}

webpack.config.js:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          ecma: undefined,
          warnings: false,
          parse: {},
          compress: { drop_console: true },
          mangle: true, // Note `mangle.properties` is `false` by default.
          module: false,
          output: { comments: false },
          toplevel: false,
          nameCache: null,
          ie8: false,
          keep_classnames: undefined,
          keep_fnames: false,
          safari10: false,
        },
      }),
    ],
  },
};

package.json:

{
  "name": "cli3pwavuetify",
  "version": "0.1.0",
  "private": true,
  ...
}

What modifications should be made for it to function properly? Is webpack.config.js the correct location for these changes?

Answer №1

When working on Vue CLI projects, you can customize Webpack configuration in the

<projectRoot>/vue.config.js
file using the configureWebpack or chainWebpack properties. To view the final Webpack config, you can use the commandvue inspect.

In your situation, create a new

<projectRoot>/vue.config.js
file and include the following code:

const TerserPlugin = require('terser-webpack-plugin')

module.exports = {
  configureWebpack: config => {
    config.optimization = {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: { drop_console: true },
            mangle: true, // Note `mangle.properties` is `false` by default.
            module: false,
            output: { comments: false },
            toplevel: false,
            nameCache: null,
            ie8: false,
            keep_classnames: undefined,
            keep_fnames: false,
            safari10: false,
          },
        }),
      ],
    }
  }
}

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

Preventing a scroll handler from executing once an element has been clicked

When a user scrolls to the video, it will automatically start playing. Similarly, when the user scrolls away from the video, it will stop playing and display the poster image. However, I encountered an issue where I don't want this functionality to tr ...

I seem to be facing some difficulty in dynamically calling my buttons in AngularJS

Can you assist me in solving this problem? I am new to Angular and just starting out. Initially, there is only one button on load called "Add list". When the user clicks on this button, they are able to add multiple lists. Each list contains a button labe ...

In ReactJS, when you encounter TextField values that are "undefined", it is important to handle them appropriately

I'm a beginner when it comes to ReactJs and Material-UI, so please bear with me if my question seems silly. Currently, I have a file named Main.js which includes the following code snippet: handleChange = (name, event) => { if(event==null) ...

Is it possible that the triangulation library functions on Firefox, but encounters compatibility issues on Chrome?

Currently, I am implementing triangulation using the Poly2Tri library. This is my code: var swctx = new poly2tri.SweepContext(contour); swctx.triangulate(); var triangles = swctx.getTriangles(); for (var w = 0; w < triangles.length; w++) { pts_t ...

Having trouble dynamically applying css properties on the element

I am facing an issue where I want to display a popup without the scroll bar showing up. The popup is being displayed using an iframe. var addPartnerDialog = App.addDialog("AddExistingPartner", 500, 250); $(addPartnerDialog.getId()).css('overfl ...

Trouble with Swiper carousel loading new slides

Currently, I am working on a project using Cordova and jQuery. I have implemented the Swiper library by idangero for handling slides. The problem arises when I add new slides and try to display them. Here is the relevant jQuery code snippet: if(row.pict ...

Retrieving information from an object using a randomly generated identifier

Imagine having an object structured like this. var foo = { "dfsghasdgsad":{ "name":"bob", "age":"27" } }; The variable foo will consistently only have one object, but the key is dynamically created. How can I access the values "bob" and "27" ...

In JavaScript, the return statement is used to halt the execution of any subsequent statements

I encountered a situation where I need to stop the execution of the next function call if the previous function has a return statement. However, I noticed that even though there is a return statement in the "b" function below, the next function call still ...

Utilize Vue and JSON to dynamically fill select options based on another select input

Seeking assistance in developing a dynamic search form with select options for Districts, Regions and locations. The Regions selection should be populated based on the selected District, and the Locations based on the chosen Region. The data is structured ...

Best practices for positioning content within a Vuetify component?

I want to modify the position of these transparent buttons in this image: https://i.sstatic.net/ePsqL.png The current alignment of the buttons - Home, Offers, About and Contact - is at the top. How can I align them to the bottom of the image instead? Be ...

ERROR: An issue occurred while attempting to resolve key-value pairs

Within my function, I am attempting to return a set of key-value pairs upon promise completion, but encountering difficulties. const getCartSummary = async(order) => { return new Promise(async(request, resolve) => { try { cons ...

Invoking a Typescript function from the Highcharts load event

Struggling to call the TypeScript function openDialog() from the events.load of Highcharts? Despite using arrow functions, you are running into issues. Take a look at the code snippet below: events: { load: () => { var chart : any = this; ...

Understanding the process of unmarshalling an array within a POST request

I am attempting to send an array of JSON data with a POST request to an API server. However, I keep encountering the following error: cannot unmarshal array into Go value of type models.UserRequest Despite trying to unmarshal the data using a factory and ...

What is the process for creating facial geometry in threeJS using the scaledMesh output from face detection with TensorFlow in JavaScript?

I am trying to generate a 3D model of a detected face using ThreeJS and the Tensorflow library for detecting faces. However, when I utilize BufferGeometry to create the face geometry, the results are not as expected. https://i.sstatic.net/DsPox.png Below ...

Combining two JSON responses using AngularJS

$scope.addUserJson = $scope.adduser; console.log($scope.addUserJson); Output Object {"username":"Mik911","firstname":"Mike","lastname":"Angel","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="563b3f3d16313b373f3a78353 ...

Having Difficulty with Splicing Arrays in React?

Currently working on learning React and trying to develop my own mini-app. I'm basing it very closely on the project showcased in this video tutorial. I've run into an issue with the comment deletion functionality in my app. Despite searching va ...

The MongoDB regex is failing to provide the expected outcome

I'm facing an issue with searching data in MongoDB. I have a table with approximately 5000 entries of data that need to be searched based on multiple columns with specific priority criteria. The first priorities for the search are symbol, name, co_nam ...

html form shifting positions based on screen resolution

I have been experimenting with a login screen design for my website recently. I created a form with a fixed position, but as the screen resolution changes, not only does the form's position shift, but also the image moves, causing an unwanted interse ...

Utilizing arrays dynamically to generate data for a bar chart display in JavaScript

I'm currently working on generating a bar stack graph using the chart.js JavaScript library. My JavaScript array contains the following data: 0: {labels: "01/01/2020 00:00:00", data: 7433, category: "A"} 1: {labels: "01/01/2020 00:00:00", data: 774, ...

What is the process for transitioning from Ajax to Fetch API in JavaScript?

Currently, I am utilizing the JavaScript version of RiveScript which relies on ajax, and I have decided to move away from using jQuery. There is a single line of ajax code that I need to update to integrate the new Fetch API. **Note: The ajax code can be ...