所以我有一个vue-js应用程序,今天我开始使用prerender-spa-plugin生成一些静态页面以获得更好的SEO。当我运行npm run build时,一切正常,没有错误。现在,当我想使用npm run serve运行开发服务器时,出现以下错误(仅部分错误)
error in ./src/main.js
Module build failed (from ./node_modules/babel-
loader/lib/index.js):
Error: .plugins[0] must include an object
at assertPluginItem (/Users/user/Desktop/app/node_modules/@babel/core/lib/config/validation/option-assertions.js:231:13)
因此,我想问题与babel插件加载程序有关。因此,我对使用prerender-spa-plugin的代码的每个部分都表示赞赏,但是仍然遇到相同的错误。我希望有人能指出我正确的方向。
我的babel.config.js
const removeConsolePlugin = []
if(process.env.NODE_ENV === 'production') {
removeConsolePlugin.push("transform-remove-console")
}
module.exports = {
presets: [
'@vue/app'
],
plugins: [removeConsolePlugin]
}
我的vue.config.js
const path = require('path');
const PrerenderSpaPlugin = require('prerender-spa-plugin');
const productionPlugins = [
new PrerenderSpaPlugin({
staticDir: path.join(__dirname, 'dist'),
routes: ['/', '/documentation'],
renderer: new PrerenderSpaPlugin.PuppeteerRenderer({
// We need to inject a value so we're able to
// detect if the page is currently pre-rendered.
inject: {},
// Our view component is rendered after the API
// request has fetched all the necessary data,
// so we create a snapshot of the page after the
// `data-view` attribute exists in the DOM.
//renderAfterElementExists: '[data-view]',
}),
}),
];
module.exports = {
configureWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.plugins.push(...productionPlugins);
}
}
}