javascript - 将“static-site-generator-webpack-plugin”添加到我的项目后出现的问题
问题描述
我刚刚在我的项目中添加了“static-site-generator-webpack-plugin”,但遇到了以下错误:
ERROR in ReferenceError: window is not defined
at main:1:224
at ContextifyScript.Script.runInContext (vm.js:59:29)
at ContextifyScript.Script.runInNewContext (vm.js:65:15)
at module.exports (/Users/johnnynolan/Repos/css-modules/node_modules/eval/eval.js:69:12)
at /Users/johnnynolan/Repos/css-modules/node_modules/static-site-generator-webpack-plugin/index.js:42:22
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/johnnynolan/Repos/css-modules/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:7:1)
at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/johnnynolan/Repos/css-modules/node_modules/tapable/lib/Hook.js:35:21)
at hooks.optimizeChunkAssets.callAsync.err (/Users/johnnynolan/Repos/css-modules/node_modules/webpack/lib/Compilation.js:1275:32)
at _err0 (eval at create (/Users/johnnynolan/Repos/css-modules/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
at /Users/johnnynolan/Repos/css-modules/node_modules/uglifyjs-webpack-plugin/dist/index.js:282:11
我的 webpack.config 如下:
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
var locals = {
routes: [
'/',
'/about'
]
};
module.exports = {
mode: 'production',
entry: './src',
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js',
libraryTarget: 'umd' // this is super important
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: __dirname + '/src',
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'),
include: __dirname + '/src'
}
],
},
plugins: [
new StaticSiteGeneratorPlugin('main', locals.routes),
new ExtractTextPlugin("styles.css")
]
};
我不确定这是否取决于我设置 webpack.config 的方式,但我的感觉是使用 'static-site-generator-webpack-plugin' 存在问题???
任何帮助将非常感激...
谢谢!
解决方案
您是否尝试过添加globalObject: 'this'
到您的输出?详情在这里
推荐阅读
- python - 将 matplotlib 模块导入 pipenv 环境 - vscode
- sql - 如何在 Oracle SQL Developer 的 json 中“选择位置”?
- c - 程序不接受第二个字符串并直接给出输出
- python - 将具有多个值的电影添加到我的 Mongo DB 表
- postgresql - 检查非重叠元素 postgres
- java - 如何解决错误“错误请求。主机和端口的组合需要 TLS。”
- swift - 无法通过链接或路径从 Firebase 数据库下载图片
- python - 如何使用 requests.get() 方法访问标签内的正文?
- javascript - 为什么在画布上绘制许多元素时页面开始滞后?
- python - 合并多个文件,将文件名作为列名