简体   繁体   English

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

[英]NUXT compress/minify/combine ccs, js and HTML

I am working on a project made using NUXT we use yarn for package management.我正在开发一个使用 NUXT 制作的项目,我们使用纱线进行包管理。

I need to compress (and perhaps combine if possible) js, css and html to speed up load time.我需要压缩(如果可能的话,也可能结合)js、css 和 html 以加快加载时间。

I read " https://www.npmjs.com/package/nuxt-compress "我读了“ https://www.npmjs.com/package/nuxt-compress

I tried to add module.export to NUXT.config.js but couldn't make it to work.我试图将 module.export 添加到 NUXT.config.js 但无法使其工作。

Will some one kindly guide me step by step how to configure compression on build time as I am new to NUXT.由于我是 NUXT 的新手,有人会一步一步地指导我如何在构建时配置压缩。

Where to put it and what command to run when I build or run the project.当我构建或运行项目时,把它放在哪里以及运行什么命令。

I guess it is doing some thing similar to what I require when I do "yarn build".我想它正在做一些类似于我在做“纱线构建”时所需要的东西。 It is minifying the css and js.它正在缩小 css 和 js。 But can we do more?但是我们可以做得更多吗? Eg gzip and combine multiple js, css or html together?例如 gzip 并将多个 js、css 或 html 组合在一起?

You can add to the build configuration of your Nuxt project using html.minify您可以使用html.minify添加到 Nuxt 项目的构建配置中

This is the currently supported configuration: https://nuxtjs.org/api/configuration-build#html-minify这是当前支持的配置: https : //nuxtjs.org/api/configuration-build#html-minify

It uses https://github.com/kangax/html-minifier behind the scenes.它在幕后使用https://github.com/kangax/html-minifier

html.minify html.minify

Type: Object类型:对象

Default:默认:

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

Attention: If you make changes to html.minify, they won't be merged with the defaults!注意:如果您对 html.minify 进行更改,它们将不会与默认值合并!

Configuration for the html-minifier plugin used to minify HTML files created during the build process (will be applied for all modes).用于缩小在构建过程中创建的 HTML 文件的 html-minifier 插件的配置(将应用于所有模式)。

This didn't work for me :(这对我不起作用:(

npm install html-minifier

in nuxt.config.js在 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
      }
    }, 
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM