Vue CLI 3 预渲染-spa-插件

问题描述 投票:0回答:2

我尝试使用 Vue CLI 3 中的 npm 包 prerender-spa-plugin 来预渲染 SPA 的路由,在运行“npm run build”后,我得到了不错的输出,如下所示: enter image description here

index.html 中的输出是错误的:

<html>

<head>
</head>

<body>Html Webpack Plugin:
  <pre>  ReferenceError: BASE_URL is not defined
  
  - index.html:96 
    C:/Users/Fred/v2/public/index.html:96:11
  
  - index.html:99 0971.module.exports
    C:/Users/Fred/v2/public/index.html:99:3
  
  - index.js:284 Promise.resolve.then
    [v2]/[html-webpack-plugin]/index.js:284:18
  
  </pre>
</body>

</html>

我的 vue.config.js 是这样的:

const path = require('path');
const PrerenderSPAPlugin = require('prerender-spa-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    configureWebpack: {
        plugins: [
            new HtmlWebpackPlugin({
                template: './public/index.html',
                inject: false
            }),
            new PrerenderSPAPlugin({
                staticDir: path.join(__dirname, './dist'),
                routes: ['/', '/om-guldbaek', '/om/:id', '/aktiviteter', '/aktivitet/:id', '/foreninger', '/forening/:id', '/begivenheder', '/begivenhed/:id', '/gdpr', '/institutioner', '/institution/:id', '/login', '/nyheder', '/nyhed/:id', '/kontakt', '/registreringer'],
            })
        ],
    },
};

当我在 VSCode 中运行“npm run build”时,它不断返回“Building for production...”,但没有任何反应。有谁知道这个问题吗?

javascript vue.js single-page-application prerender
2个回答
0
投票

好吧,我发现了问题。在index.html 中我有这样一行:

<link rel="icon" href="<%= BASE_URL %>favicon.ico">

现在已经解决了


0
投票

怎么解决的?看来我的错误也是由于 favico 在此输入图片描述

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.