NUXT压缩/缩小/组合ccs、js和HTML



我正在做一个使用NUXT的项目,我们使用yarn进行包管理。

我需要压缩js、css和html(如果可能的话,还可以合并(以加快加载时间。

我读到"https://www.npmjs.com/package/nuxt-compress">

我试图将module.export添加到NUXT.config.js,但无法正常工作。

有人会一步一步地指导我如何在构建时配置压缩吗?因为我是NUXT的新手。

在构建或运行项目时,将它放在哪里以及运行什么命令。

我想这是在做一些类似于我做"纱线构建"时所要求的事情。它正在缩小css和js。但我们能做得更多吗?例如,gzip并将多个js、css或html组合在一起?

您可以使用html.minify添加到Nuxt项目的构建配置中

这是当前支持的配置:https://nuxtjs.org/api/configuration-build#html-迷你

它使用https://github.com/kangax/html-minifier在幕后。

html.minify

类型:对象

默认值:

{
collapseBooleanAttributes: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
trimCustomFragments: true,
useShortDoctype: true
}

注意:如果您对html.minify进行更改,它们将不会与默认值合并!

用于缩小生成过程中创建的html文件的html缩小程序插件的配置(将应用于所有模式(。

这对我不起作用:(

npm install html-minifier

在nuxt.config.js 中

build: {
html: {
minify:{
collapseBooleanAttributes: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
trimCustomFragments: true,
useShortDoctype: true,
removeComments: true,
preserveLineBreaks: false,
collapseWhitespace: true
}
}, 
},

最新更新