我正在构建一个安装了 vue-cli-plugin-compression 和 vue-cli-plugin-prerender-spa 的 vue cli 3 应用程序。(在引擎盖下,这些使用 prerender-spa-plugin 和 compression-webpack-plugin)。
prerender-spa-plugin 将 index.html 重命名为 app.html。然后预呈现 app.html 并将生成的 html 存储在新的 index.html 中。页面已正确预呈现,并且 app.html 已正确压缩。但是,生成的 index.html(作为预呈现结果的页面)未压缩。我怎样才能让预渲染的结果也被 gzip 压缩?
这是我的 vue.config.js:
module.exports = {
devServer: {
port: 3000
},
configureWebpack: {
devtool: 'source-map'
},
pluginOptions: {
prerenderSpa: {
customRendererConfig: {
injectProperty: '__PRERENDER_INJECTED',
inject: {},
},
registry: undefined,
renderRoutes: [
'/'
],
useRenderEvent: true,
headless: true,
onlyProduction: true,
postProcess: route => {
// Defer scripts and tell Vue it's been server rendered to trigger hydration
route.html = route.html
.replace(/<script (.*?)>/g, '<script $1 defer>')
.replace('id="app"', 'id="app" data-server-rendered="true"');
return route;
}
},
compression:{
gzip: {
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|js\.map|css|html)$/,
minRatio: 0.8,
}
}
}
};
我尝试在压缩前进行预渲染,但它并没有改变任何东西:
chainWebpack: (config) => {
config.plugin('pre-render').before('gzip-compression');
config.plugin('gzip-compression').after('html');
},
白猪掌柜的
相关分类