NuxtJS v2 如何将.nuxt/views目录下的app.template.html重命名为index.html
app.template.html to index.html in Nuxt.js v2 Hey there! I totally get why you’d want to rename that template file, but let’s start with a crucial note: never manually edit files in the .nuxt directory. This folder is auto-generated by Nuxt every time you run npm run dev or npm run build—any changes you make here will get wiped out on the next build. Instead, we’ll use Nuxt’s built-in tools to set up a custom template with your desired filename.
Here’s how to solve this properly:
1. Create a Custom HTML Template in Your Project Root
Skip editing the auto-generated app.template.html and make your own template right in your project’s root folder. Name it index.html (since that’s what you want to use) and paste in the default template content (you can copy this from the original .nuxt/views/app.template.html to keep everything consistent):
<!DOCTYPE html> <html {{ HTML_ATTRS }}> <head {{ HEAD_ATTRS }}> {{ HEAD }} </head> <body {{ BODY_ATTRS }}> {{ APP }} </body> </html>
Don’t remove those template variables like {{ HEAD }} or {{ APP }}—they’re how Nuxt injects your app’s content, meta tags, and critical assets into the final HTML.
2. Configure Nuxt to Use Your New Template
Open your nuxt.config.js file and add the html configuration option to tell Nuxt to use your custom index.html template:
export default { // Your existing Nuxt config options... html: { template: './index.html' // Path to your custom template file } }
3. Test the Change
Restart your Nuxt dev server or run a fresh build. Now Nuxt will use your index.html template as the base, and you won’t have to worry about your changes getting overwritten anymore.
A quick side note: If your end goal is to have the final built HTML file named index.html, Nuxt actually does this by default—you’ll find it in the dist folder after running npm run build. The steps above are specifically for customizing the template file itself to be named index.html during development and builds.
内容的提问来源于stack exchange,提问作者Nour Basha

