mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat: abstract minify and use value for all modes (#3965)
* feat: abstract minify and use value for all modes * change name to htmlMinify * only override htmlMinify with legacy value in generate mode * Use default options for htmlMinify and add override info to warning * Remove redundant minification settings * Override minification settings in generator * Cleanup and add TODO for nuxt 3 * Improve warning * set default minify option to "true" * make tests pass again * remove the culprit * replace htmlMinify with html.minify
This commit is contained in:
parent
bc9071663f
commit
d69b4b8b12
@ -4,7 +4,7 @@ import htmlMinifier from 'html-minifier'
|
||||
import Chalk from 'chalk'
|
||||
import fsExtra from 'fs-extra'
|
||||
import consola from 'consola'
|
||||
import { isUrl, promisifyRoute, waitFor, flatRoutes } from '../common/utils'
|
||||
import { flatRoutes, isUrl, promisifyRoute, waitFor } from '../common/utils'
|
||||
|
||||
export default class Generator {
|
||||
constructor(nuxt, builder) {
|
||||
@ -223,9 +223,19 @@ export default class Generator {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.options.generate.minify) {
|
||||
let minificationOptions = this.options.build.html.minify
|
||||
|
||||
// Legacy: Override minification options with generate.minify if present
|
||||
// TODO: Remove in Nuxt version 3
|
||||
if (typeof this.options.generate.minify !== 'undefined') {
|
||||
minificationOptions = this.options.generate.minify
|
||||
consola.warn('generate.minify has been deprecated and will be removed in the next major version.' +
|
||||
' Use build.html.minify instead!')
|
||||
}
|
||||
|
||||
if (minificationOptions) {
|
||||
try {
|
||||
html = htmlMinifier.minify(html, this.options.generate.minify)
|
||||
html = htmlMinifier.minify(html, minificationOptions)
|
||||
} catch (err) /* istanbul ignore next */ {
|
||||
const minifyErr = new Error(
|
||||
`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`
|
||||
|
@ -63,7 +63,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
new HTMLPlugin({
|
||||
filename: '../server/index.ssr.html',
|
||||
template: this.options.appTemplatePath,
|
||||
minify: true,
|
||||
minify: this.options.build.html.minify,
|
||||
inject: false // Resources will be injected using bundleRenderer
|
||||
})
|
||||
)
|
||||
@ -73,7 +73,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
new HTMLPlugin({
|
||||
filename: '../server/index.spa.html',
|
||||
template: this.options.appTemplatePath,
|
||||
minify: true,
|
||||
minify: this.options.build.html.minify,
|
||||
inject: true,
|
||||
chunksSortMode: 'dependency'
|
||||
}),
|
||||
|
@ -116,6 +116,20 @@ export default {
|
||||
stage: 2
|
||||
}
|
||||
},
|
||||
html: {
|
||||
minify: {
|
||||
collapseBooleanAttributes: true,
|
||||
decodeEntities: true,
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
processConditionalComments: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeRedundantAttributes: true,
|
||||
trimCustomFragments: true,
|
||||
useShortDoctype: true
|
||||
}
|
||||
},
|
||||
|
||||
templates: [],
|
||||
watch: [],
|
||||
devMiddleware: {},
|
||||
@ -140,27 +154,7 @@ export default {
|
||||
concurrency: 500,
|
||||
interval: 0,
|
||||
subFolders: true,
|
||||
fallback: '200.html',
|
||||
minify: {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: false,
|
||||
decodeEntities: true,
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
processConditionalComments: true,
|
||||
removeAttributeQuotes: false,
|
||||
removeComments: false,
|
||||
removeEmptyAttributes: true,
|
||||
removeOptionalTags: false,
|
||||
removeRedundantAttributes: true,
|
||||
removeScriptTypeAttributes: false,
|
||||
removeStyleLinkTypeAttributes: false,
|
||||
removeTagWhitespace: false,
|
||||
sortAttributes: true,
|
||||
sortClassName: false,
|
||||
trimCustomFragments: true,
|
||||
useShortDoctype: true
|
||||
}
|
||||
fallback: '200.html'
|
||||
},
|
||||
env: {},
|
||||
head: {
|
||||
|
Loading…
Reference in New Issue
Block a user