Skip to content

Commit

Permalink
fix: pass all Node.js globals to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 9, 2023
1 parent 6d740e6 commit 9af39c1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
52 changes: 50 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,56 @@ class HtmlWebpackPlugin {
HTML_WEBPACK_PLUGIN: true,
require: require,
htmlWebpackPluginPublicPath: publicPath,
URL: require('url').URL,
__filename: templateWithoutLoaders
__filename: templateWithoutLoaders,
__dirname: path.dirname(templateWithoutLoaders),
AbortController: global.AbortController,
AbortSignal: global.AbortSignal,
Blob: global.Blob,
Buffer: global.Buffer,
ByteLengthQueuingStrategy: global.ByteLengthQueuingStrategy,
BroadcastChannel: global.BroadcastChannel,
CompressionStream: global.CompressionStream,
CountQueuingStrategy: global.CountQueuingStrategy,
Crypto: global.Crypto,
CryptoKey: global.CryptoKey,
CustomEvent: global.CustomEvent,
DecompressionStream: global.DecompressionStream,
Event: global.Event,
EventTarget: global.EventTarget,
File: global.File,
FormData: global.FormData,
Headers: global.Headers,
MessageChannel: global.MessageChannel,
MessageEvent: global.MessageEvent,
MessagePort: global.MessagePort,
PerformanceEntry: global.PerformanceEntry,
PerformanceMark: global.PerformanceMark,
PerformanceMeasure: global.PerformanceMeasure,
PerformanceObserver: global.PerformanceObserver,
PerformanceObserverEntryList: global.PerformanceObserverEntryList,
PerformanceResourceTiming: global.PerformanceResourceTiming,
ReadableByteStreamController: global.ReadableByteStreamController,
ReadableStream: global.ReadableStream,
ReadableStreamBYOBReader: global.ReadableStreamBYOBReader,
ReadableStreamBYOBRequest: global.ReadableStreamBYOBRequest,
ReadableStreamDefaultController: global.ReadableStreamDefaultController,
ReadableStreamDefaultReader: global.ReadableStreamDefaultReader,
Response: global.Response,
Request: global.Request,
SubtleCrypto: global.SubtleCrypto,
DOMException: global.DOMException,
TextDecoder: global.TextDecoder,
TextDecoderStream: global.TextDecoderStream,
TextEncoder: global.TextEncoder,
TextEncoderStream: global.TextEncoderStream,
TransformStream: global.TransformStream,
TransformStreamDefaultController: global.TransformStreamDefaultController,
URL: global.URL,
URLSearchParams: global.URLSearchParams,
WebAssembly: global.WebAssembly,
WritableStream: global.WritableStream,
WritableStreamDefaultController: global.WritableStreamDefaultController,
WritableStreamDefaultWriter: global.WritableStreamDefaultWriter
});
const vmScript = new vm.Script(source, { filename: templateWithoutLoaders });
// Evaluate code and cast to string
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
},
"devDependencies": {
"@types/node": "11.13.9",
"@types/node": "^20.2.5",
"commitizen": "^4.2.4",
"css-loader": "5.0.1",
"cz-conventional-changelog": "2.1.0",
Expand Down

0 comments on commit 9af39c1

Please # to comment.