Vue CLI 3 prerender-spa-plugin

时间:2019-01-18 08:36:21

标签: javascript vue.js single-page-application prerender

我已经尝试通过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 ...”,没有任何反应。有人知道这个问题吗?

1 个答案:

答案 0 :(得分:1)

好的,我发现了问题。在index.html中,有以下一行:

class UserForm(...):
    ...
    def save(self, **kwargs):
       user = super(UserForm, self).save(commit=False)
       password = self.cleaned_data.get('password')
       user.set_password(password)
       user.save()
       return user

所以现在它已修复