美文网首页
预渲染webpack配置

预渲染webpack配置

作者: 用技术改变世界 | 来源:发表于2020-11-02 09:25 被阅读0次

    在 main.js文件

    prerender-spa-plugin

    const PrerenderSPAPlugin = require('prerender-spa-plugin')

    if (envLowerCase !== 'dev') {

      webpackConfig.plugins.push(new PrerenderSPAPlugin({

        // Required - The path to the webpack-outputted app to prerender.

        staticDir: path.resolve(

          __dirname,

          '../OUTPUT/' + envLowerCase.toUpperCase()

        ),

        // Required - Routes to render.

        routes: ['/', '/customer-management', '/customer-create', '/customer-overview', '/customer-edit', '/customer-detail' ,'/customer-overview',

        '/redemption-register-list',  '/redemption-flow-list',  '/redemption-list'],

        // minify: {

        //   collapseBooleanAttributes: true,

        //   collapseWhitespace: true,

        //   decodeEntities: true,

        //   keepClosingSlash: true,

        //   sortAttributes: true

        // },

        postProcessHtml: function (context) {

          var html = context.html

          html = html.replace(/<base href=\"http:\/\/localhost:8000\/[A-Za-z\-]+\">/, '')

          return html

        },

         renderer: new PrerenderSPAPlugin.PuppeteerRenderer({

          headless: true,

          renderAfterDocumentEvent: 'render-event'

        })

      }));

    }

    相关文章

      网友评论

          本文标题:预渲染webpack配置

          本文链接:https://www.haomeiwen.com/subject/hpvpvktx.html