Content of "index.html" in Vue CLI

Every time I execute npm run build, it creates a dist folder containing my app - all well and good, but...

Issue at Hand:

Upon opening my index.html, I find the

<!DOCTYPE>, <head>, <body>
tags, whereas in my case, all I really need is the <div id="app"> with the CSS and JS files.

Query:

Is there a way to omit the unnecessary tags that are being generated, such as

<!DOCTYPE>, <body>, <head>
in my specific scenario?

When I run npm run build, I would like the resulting index.html to look like this:

<link href=/testing/path/css/app.6878f4f8.css rel=preload as=style>
<link href=/testing/path/js/app.457dc9d3.js rel=preload as=script>
<link href=/testing/path/js/chunk-vendors.a0cfb1f1.js rel=preload as=script>
<link href=/testing/path/css/app.6878f4f8.css rel=stylesheet>
 <div id=app>
 </div>
<script src=/testing/path/js/chunk-vendors.a0cfb1f1.js></script>
<script src=/testing/path/js/app.457dc9d3.js></script>

Otherwise, I have to manually edit the file every time.

Answer №1

When working with Vue CLI generated projects, the public/index.html file serves as a template that includes headers and tags you may want to avoid. The only essential element for Vue in this file is <div id="app"></div>, so it's safe to remove everything else from public/index.html.

It's worth noting that the preload, prefetch, and CSS plugins (which are enabled by default) will automatically insert a <head> section. If you wish to disable the preload and prefetch plugins, you can do so using the following configuration:

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.plugins.delete('prefetch')
    config.plugins.delete('preload')
  }
}

After making these changes, your final HTML output will resemble the following:

<head><link href=/css/app.e2713bb0.css rel=stylesheet></head>
<div id=app></div>
<script src=/js/chunk-vendors.327f60f7.js></script>
<script src=/js/app.fb8740dd.js></script>

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

The scrolling event on the div is not triggering

I'm struggling with this piece of code: const listElm = document.querySelector('#infinite-list'); listElm.addEventListener('scroll', e => { if(listElm.scrollTop + listElm.clientHeight >= listElm.scrollHeight) { th ...

Personalizing the display of Vuetify pagination controls

I've implemented the vuetify pagination with the following code snippet: <v-pagination v-model="page" :length="n" total-visible="7" ></v-pagination> When n is greater than 7, if you're on the first few pages, it will display b ...

employing a flexible array of gulp operations in run-sequence

I have a situation where I need to create gulp tasks with dynamic names and ensure that they run in sequence, not parallel. I have stored the task names in an array, but when I try to use run-sequence, I encounter an error. I suspect the issue lies in how ...

What is the process for creating an input configuration file for the function?

Within the file rsync.js, there exists a function: rsync.js var onClick = function(){ exec('rsync -avz -e "ssh -o StrictHostKeyChecking=no -o\ UserKnownHostsFile = /dev/null" --progress' + src_dir + to_dir,\ function(error,stdo ...

tips for sending a chosen item to the Vujes API

How can I send the selected item from a dropdown to an API in Vue.js? <select :v-model="selectedRole" class="custSelect"> <option v-for="option in options" v-bind:value="option.value"> {{option.role}} </option> ...

Using ngFor in Angular 6 to create a table with rowspan functionality

Check out this functional code snippet Desire for the table layout: <table class="table table-bordered "> <thead> <tr id="first"> <th id="table-header"> <font color="white">No.</font> </th> <th id="table-hea ...

The Firefox extension is experiencing an issue with loading moment.js before chart.js

I've been working on porting a Chrome extension to Firefox that includes Chartjs charts on a page. It runs perfectly on Chrome, but I've encountered an issue when trying to transition it to Firefox. The charts fail to load and an error message di ...

The process of displaying custom number buttons on the correct input field in react.js

I am facing a challenge in implementing this feature. I have created custom number buttons from 0-9 that users can click on instead of using the keyboard. The issue arises when there are multiple dynamically generated input fields based on JSON Data. For e ...

Every time I try to install create-react-app, I keep encountering a frustrating 'network Socket timeout' error

$ npx create-react-app amazon-clone npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. Creating a new React app in D:\js\faceboom. npm WARN config global `--global`, `--local` are deprecated. ...

Issue with JQuery on Mobile Devices: Troubles with Dropdown Menu and Loading Function

Having some trouble with my JQuery code on mobile devices. The drop down menu isn't showing up on an iPhone, the load function isn't working to display the additional PHP page on a Samsung Edge 7, and the drop down doesn't seem to be functio ...

The Gatsby and React navigator

Hey there, I've run into a little snag while working on my React component. I'm trying to display a pop-up using JS, but when I try to build my Gatsby site, I encounter an error stating: WebpackError: ReferenceError: navigator is not defined. Bel ...

Load the page using AJAX and automatically scroll to the anchor within the loaded content

I want to achieve an automatic scroll to the beginning of a loaded page after using ajax to load it. Here is the code snippet I currently have: html <button class="btn btn-info btn-lg" type="button" id="photos"> <i class="fa fa-plus fa-5x">&l ...

Tips for implementing an active class for td within jQuery tabs?

I'm currently using Jquery tabs within a table, and it's working fine. However, I need to activate the td when its link is clicked. Here's my code: $(document).ready(function() { $(".vertical_tabs_menu a").click(function(event) { ...

Exploring the world of Vue and Nuxt: delving into the depths

For years, I've been using Vue as a client-side library without delving into server-side rendering. Recently, I came across some tutorials on the topic and noticed a difference between normal client-side fetching with the mount() hook. <template> ...

Upon refreshing the page, an inline script was not executed due to its violation of the Content Security Policy directive: "script-src 'self'"

When I refresh the page on my production build for all routes except "/", I encounter an error in my Node/React app which results in a blank page being displayed. The error message states: "Refused to execute inline script because it violates the followi ...

Using ANT to swap out values in JavaScript code

My HTML page includes a <script> tag with the following code: <script type="text/javascript"> window.location ="THIRD PARTY URL" </script> The code above functions correctly. Now, I need to change the value of the Third Party URL f ...

Steps to completely eliminate all elements from an object using specific keys

I have been pondering the most efficient method to delete all elements of an object through an onClick function. The goal is for the handler to remove all elements. Despite attempts with methods like the delete keyword and filtering, clicking the clear all ...

Why is there empty white space showing in the select option drop down, even though the data is being bound correctly

When creating a dynamic dropdown on Angular 7 at runtime, I am facing an issue where there is whitespace visible in the select options. Despite correctly binding and filling the data, this white space persists. How can I remove this blank area when binding ...

Vue.js - dynamically applying CSS classes based on conditions

Within a VueNative project that utilizes NativeBase as a component library, with tags prefixed by nb-, the code snippet below is found within the <template> tags of the footer.vue file which houses navigation buttons. This piece of logic successfully ...

Having trouble with importing files from a different folder in a React Typescript project

I have a specific folder arrangement set up https://i.sstatic.net/GFOYv.png My goal is to bring both MessageList.tsx and MessageSent.tsx into my Chat.tsx file // Chat.tsx import React from 'react' import {MessageList, MessageSent} from "./ ...