nuxt项目配置nuxt.confg.js,使网页源代码优化排版,删除乱码
时间: 2024-03-20 16:33:31 浏览: 104
创建nuxt.js项目流程图解
可以通过以下几个方式优化网页源代码排版:
1. 使用prettier工具进行代码格式化,可以在nuxt.config.js中添加以下配置:
```
build: {
extend(config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: "pre",
test: /\.(js|vue)$/,
loader: "eslint-loader",
exclude: /(node_modules)/
});
// Prettier configuration
config.module.rules.push({
test: /\.(js|vue)$/,
loader: "prettier-loader",
exclude: /(node_modules)/,
options: {
// Prettier options
printWidth: 120,
singleQuote: true,
trailingComma: "none"
}
});
}
}
}
```
2. 使用vue-meta插件来管理网页的meta信息,可以在nuxt.config.js中添加以下配置:
```
head: {
title: "My Website",
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "My website description" }
]
},
plugins: [
{ src: "@/plugins/vue-meta", ssr: true }
]
```
3. 使用vue-favicon插件来管理网页的favicon图标,可以在nuxt.config.js中添加以下配置:
```
head: {
link: [
{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }
]
},
plugins: [
{ src: "@/plugins/vue-favicon", ssr: true }
]
```
4. 去除网页中的乱码,可以在nuxt.config.js中添加以下配置:
```
head: {
meta: [
{ charset: "utf-8" }
]
}
```
阅读全文