一些上下文:我正在尝试使用static-site-generator-webpack-plugin
来创建一个服务器端静态网站。
有人可能会帮我解决,请注意以下错误:
ERROR in TypeError: Cannot read property 'search' of undefined
at Object.eval (webpack:///(webpack)-dev-server/client?:31:28)
at eval (webpack:///(webpack)-dev-server/client?:248:30)
at Object../node_modules/webpack-dev-server/client/index.js?http://localhost:8081 (evalmachine.<anonymous>:276:1)
at __webpack_require__ (evalmachine.<anonymous>:30:30)
at eval (webpack:///multi_(webpack)-dev-server/client?:1:1)
at Object.0 (evalmachine.<anonymous>:377:1)
at __webpack_require__ (evalmachine.<anonymous>:30:30)
at evalmachine.<anonymous>:79:18
at evalmachine.<anonymous>:82:10
at webpackUniversalModuleDefinition (evalmachine.<anonymous>:3:20)
我用来启动服务器的命令是webpack-dev-server --mode development
版本是:
static-site-generator-webpack-plugin: ^3.4.1
webpack-cli: ^2.1.3
webpack: ^4.8.1,
webpack-dev-server: ^3.1.4
node: 8.11.1
我的网站包装如下:
/*global require, module*/
const path = require("path")
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin')
module.exports = {
entry: "./src/entry.js",
output: {
filename: 'index.js',
path: path.resolve("dist"),
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader", "sass-loader"]
})
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: "babel-loader"
}
]
},
plugins: [
new ExtractTextPlugin("dist/styles/main.css"),
new StaticSiteGeneratorPlugin({
paths: [
'/'
],
globals: {
window: {}
}
})
]
}
最后,输入文件如下所示:
module.exports = function render(locals) {
return '<html>Hello World</html>'
}
我很感激有关我遇到的问题的任何反馈。这是我第一次使用这个插件。
链接:
答案 0 :(得分:0)
正如上述评论中提到的lukas-reineke:
插件在很长一段时间内没有更新。您是否尝试使用较旧的Webpack版本?它可能与4不兼容。
我使用了webpack 2.3.3
和webpack-dev-server 1.16.4
对于对样板感兴趣的人,我发现使用此插件的react isomorphic static site generator boilerplate。