Webpack config:
const path = require('path');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
module.exports = {
mode: 'production',
entry: './src/index.ts',
target: 'node',
output: {
filename: "index.js",
path: path.resolve(__dirname, 'dist'),
libraryTarget: "umd",
clean: true,
globalObject: 'this',
},
resolve: {
extensions: ['.ts', '.tsx']
},
externals: {
react: 'react'
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.(ts|tsx)?$/,
use: ['ts-loader'],
exclude: /node_modules/
}
]
},
plugins: [
new StaticSiteGeneratorPlugin({
globals: {
window: {}
}
})
],
}
Ошибка:
ERROR in ReferenceError: document is not defined
at Object.insertStyleElement (evalmachine.<anonymous>:590:17)
at Object.domAPI (evalmachine.<anonymous>:681:30)
at addElementStyle (evalmachine.<anonymous>:485:21)
at modulesToDom (evalmachine.<anonymous>:469:21)
at module.exports (evalmachine.<anonymous>:506:25)
at evalmachine.<anonymous>:865:48
at evalmachine.<anonymous>:1168:3
at evalmachine.<anonymous>:1171:12
at webpackUniversalModuleDefinition (evalmachine.<anonymous>:3:20)
at evalmachine.<anonymous>:10:3
webpack 5.75.0 compiled with 1 error in 5623 ms
globalObject: `(typeof self !== 'undefined' ? self : this)` не предлагать, тоже не работает.