node_modules
.bin
@ampproject
@babel
@discoveryjs
@gar
@istanbuljs
@jridgewell
@leichtgewicht
@npmcli
@riotjs
@tootallnate
@types
@ungap
@webassemblyjs
@webpack-cli
@xtuc
abab
abbrev
accepts
acorn
acorn-globals
acorn-import-assertions
acorn-walk
agent-base
agentkeepalive
aggregate-error
ajv
ajv-formats
ajv-keywords
ansi-colors
ansi-html-community
ansi-regex
ansi-styles
anymatch
append-transform
aproba
archy
are-we-there-yet
argparse
array-flatten
arrify
assertion-error
ast-types
async-foreach
asynckit
babel-plugin-dynamic-import-node
babel-plugin-polyfill-corejs2
babel-plugin-polyfill-corejs3
babel-plugin-polyfill-regenerator
balanced-match
batch
bianco.attr
bianco.dom-to-array
bianco.events
bianco.query
big.js
binary-extensions
body-parser
bonjour-service
boolbase
brace-expansion
braces
browser-process-hrtime
browser-stdout
browserslist
buffer-from
bytes
cacache
caching-transform
call-bind
camel-case
camelcase
camelcase-keys
caniuse-lite
chai
chalk
check-error
chokidar
chownr
chrome-trace-event
clean-css
clean-stack
cliui
clone-deep
color-convert
color-name
color-support
colorette
combined-stream
commander
commondir
compressible
compression
concat-map
connect-history-api-fallback
console-control-strings
content-disposition
content-type
convert-source-map
cookie
cookie-signature
core-js-compat
core-util-is
cross-spawn
css-select
css-what
cssesc
cssom
cssstyle
cumpa
curri
data-urls
debug
decamelize
decamelize-keys
decimal.js
deep-eql
deep-is
default-gateway
default-require-extensions
define-lazy-prop
define-properties
delayed-stream
delegates
depd
destroy
detect-node
diff
dns-equal
dns-packet
dom-converter
dom-nodes
dom-serializer
domelementtype
domexception
domhandler
domutils
dot-case
ee-first
electron-to-chromium
emoji-regex
emojis-list
encodeurl
encoding
enhanced-resolve
entities
env-paths
envinfo
err-code
erre
error-ex
es-module-lexer
es6-error
escalade
escape-html
escape-string-regexp
escodegen
eslint-scope
esm
esprima
esrecurse
estraverse
esutils
etag
eventemitter3
events
execa
express
fast-deep-equal
fast-json-stable-stringify
fast-levenshtein
fastest-levenshtein
faye-websocket
fill-range
finalhandler
find-up
flat
follow-redirects
foreground-child
form-data
forwarded
fresh
fromentries
fs-minipass
fs-monkey
fs.realpath
function-bind
gauge
gaze
gensync
get-caller-file
get-func-name
get-intrinsic
get-package-type
get-stdin
get-stream
glob
glob-parent
glob-to-regexp
globals
globule
graceful-fs
growl
handle-thing
hard-rejection
has
has-flag
has-property-descriptors
has-symbols
has-unicode
hasha
he
hosted-git-info
hpack.js
html-encoding-sniffer
html-entities
html-escaper
html-minifier-terser
html-webpack-plugin
htmlparser2
http-cache-semantics
http-deceiver
http-errors
http-parser-js
http-proxy
http-proxy-agent
http-proxy-middleware
https-proxy-agent
human-signals
humanize-ms
iconv-lite
imurmurhash
indent-string
infer-owner
inflight
inherits
interpret
ip
ipaddr.js
is-arrayish
is-binary-path
is-core-module
is-docker
is-extglob
is-fullwidth-code-point
is-glob
is-lambda
is-number
is-plain-obj
is-plain-object
is-potential-custom-element-name
is-stream
is-typedarray
is-windows
is-wsl
isarray
isexe
isobject
istanbul-lib-coverage
istanbul-lib-hook
istanbul-lib-instrument
istanbul-lib-processinfo
istanbul-lib-report
istanbul-lib-source-maps
istanbul-reports
jest-worker
js-base64
js-tokens
js-yaml
jsdom
jsdom-global
jsesc
json-parse-even-better-errors
json-schema-traverse
json5
kind-of
levn
lines-and-columns
loader-runner
locate-path
lodash
lodash.debounce
lodash.flattendeep
log-symbols
loupe
lower-case
lru-cache
make-fetch-happen
map-obj
media-typer
memfs
meow
merge-descriptors
merge-stream
methods
micromatch
mime
mime-db
mime-types
mimic-fn
min-indent
minimalistic-assert
minimatch
minimist-options
minipass
minipass-collect
minipass-fetch
minipass-flush
minipass-pipeline
minipass-sized
minizlib
mkdirp
mocha
ms
multicast-dns
nan
nanoid
negotiator
neo-async
no-case
node-forge
node-gyp
node-preload
node-releases
node-sass
nopt
normalize-package-data
normalize-path
npm-run-path
npmlog
nth-check
nwsapi
nyc
object-inspect
object-keys
object.assign
obuf
on-finished
on-headers
once
onetime
open
optionator
p-limit
p-locate
p-map
p-retry
p-try
package-hash
param-case
parse-json
parse5
parseurl
pascal-case
path-exists
path-is-absolute
path-key
path-parse
path-to-regexp
pathval
picocolors
picomatch
pirates
prelude-ls
pretty-error
process-nextick-args
process-on-spawn
promise-inflight
promise-retry
proxy-addr
psl
punycode
qs
quick-lru
randombytes
range-parser
raw-body
rawth
read-pkg
read-pkg-up
readable-stream
readdirp
recast
rechoir
redent
regenerate
regenerate-unicode-properties
regenerator-runtime
regenerator-transform
regexpu-core
regjsgen
regjsparser
relateurl
release-zalgo
renderkid
require-directory
require-from-string
require-main-filename
requires-port
resolve
retry
rimraf
riot
ruit
safe-buffer
safer-buffer
sass-graph
saxes
schema-utils
scss-tokenizer
select-hose
selfsigned
semver
send
serialize-javascript
serve-index
serve-static
set-blocking
setprototypeof
shallow-clone
shebang-command
shebang-regex
side-channel
signal-exit
smart-buffer
sockjs
socks
socks-proxy-agent
source-map
source-map-support
spawn-wrap
spdx-correct
spdx-exceptions
spdx-expression-parse
spdx-license-ids
spdy
spdy-transport
sprintf-js
ssri
statuses
stdout-stream
string-width
string_decoder
strip-ansi
strip-final-newline
strip-indent
strip-json-comments
supports-color
symbol-tree
tapable
tar
terser
terser-webpack-plugin
test-exclude
thunky
to-fast-properties
to-regex-range
toidentifier
tough-cookie
tr46
trim-newlines
true-case-path
tslib
type-check
type-detect
type-fest
type-is
typedarray-to-buffer
unicode-canonical-property-names-ecmascript
unicode-match-property-ecmascript
unicode-match-property-value-ecmascript
unicode-property-aliases-ecmascript
unique-filename
unique-slug
universalify
unpipe
update-browserslist-db
uri-js
util-deprecate
utila
utils-merge
uuid
validate-npm-package-license
vary
w3c-hr-time
w3c-xmlserializer
watchpack
wbuf
webidl-conversions
webpack
webpack-cli
webpack-dev-middleware
webpack-dev-server
bin
client
clients
modules
utils
index.js
overlay.js
socket.js
lib
types
LICENSE
README.md
package.json
webpack-merge
webpack-sources
websocket-driver
websocket-extensions
whatwg-encoding
whatwg-mimetype
whatwg-url
which
which-module
wide-align
wildcard
word-wrap
workerpool
wrap-ansi
wrappy
write-file-atomic
ws
xml-name-validator
xmlchars
y18n
yallist
yargs
yargs-parser
yargs-unparser
yocto-queue
.package-lock.json
src
LICENSE
package-lock.json
package.json
readme.md
webpack.config.js
309 lines
8.6 KiB
JavaScript
309 lines
8.6 KiB
JavaScript
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
|
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
|
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
|
|
/* global __resourceQuery, __webpack_hash__ */
|
|
/// <reference types="webpack/module" />
|
|
import webpackHotLog from "webpack/hot/log.js";
|
|
import stripAnsi from "./utils/stripAnsi.js";
|
|
import parseURL from "./utils/parseURL.js";
|
|
import socket from "./socket.js";
|
|
import { formatProblem, show, hide } from "./overlay.js";
|
|
import { log, logEnabledFeatures, setLogLevel } from "./utils/log.js";
|
|
import sendMessage from "./utils/sendMessage.js";
|
|
import reloadApp from "./utils/reloadApp.js";
|
|
import createSocketURL from "./utils/createSocketURL.js";
|
|
/**
|
|
* @typedef {Object} Options
|
|
* @property {boolean} hot
|
|
* @property {boolean} liveReload
|
|
* @property {boolean} progress
|
|
* @property {boolean | { warnings?: boolean, errors?: boolean, trustedTypesPolicyName?: string }} overlay
|
|
* @property {string} [logging]
|
|
* @property {number} [reconnect]
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} Status
|
|
* @property {boolean} isUnloading
|
|
* @property {string} currentHash
|
|
* @property {string} [previousHash]
|
|
*/
|
|
|
|
/**
|
|
* @type {Status}
|
|
*/
|
|
|
|
var status = {
|
|
isUnloading: false,
|
|
// TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
|
|
// eslint-disable-next-line camelcase
|
|
currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
|
|
};
|
|
/** @type {Options} */
|
|
|
|
var options = {
|
|
hot: false,
|
|
liveReload: false,
|
|
progress: false,
|
|
overlay: false
|
|
};
|
|
var parsedResourceQuery = parseURL(__resourceQuery);
|
|
var enabledFeatures = {
|
|
"Hot Module Replacement": false,
|
|
"Live Reloading": false,
|
|
Progress: false,
|
|
Overlay: false
|
|
};
|
|
|
|
if (parsedResourceQuery.hot === "true") {
|
|
options.hot = true;
|
|
enabledFeatures["Hot Module Replacement"] = true;
|
|
}
|
|
|
|
if (parsedResourceQuery["live-reload"] === "true") {
|
|
options.liveReload = true;
|
|
enabledFeatures["Live Reloading"] = true;
|
|
}
|
|
|
|
if (parsedResourceQuery.progress === "true") {
|
|
options.progress = true;
|
|
enabledFeatures.Progress = true;
|
|
}
|
|
|
|
if (parsedResourceQuery.overlay) {
|
|
try {
|
|
options.overlay = JSON.parse(parsedResourceQuery.overlay);
|
|
} catch (e) {
|
|
log.error("Error parsing overlay options from resource query:", e);
|
|
} // Fill in default "true" params for partially-specified objects.
|
|
|
|
|
|
if (typeof options.overlay === "object") {
|
|
options.overlay = _objectSpread({
|
|
errors: true,
|
|
warnings: true
|
|
}, options.overlay);
|
|
}
|
|
|
|
enabledFeatures.Overlay = true;
|
|
}
|
|
|
|
if (parsedResourceQuery.logging) {
|
|
options.logging = parsedResourceQuery.logging;
|
|
}
|
|
|
|
if (typeof parsedResourceQuery.reconnect !== "undefined") {
|
|
options.reconnect = Number(parsedResourceQuery.reconnect);
|
|
}
|
|
|
|
logEnabledFeatures(enabledFeatures);
|
|
/**
|
|
* @param {string} level
|
|
*/
|
|
|
|
function setAllLogLevel(level) {
|
|
// This is needed because the HMR logger operate separately from dev server logger
|
|
webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
|
|
setLogLevel(level);
|
|
}
|
|
|
|
if (options.logging) {
|
|
setAllLogLevel(options.logging);
|
|
}
|
|
|
|
self.addEventListener("beforeunload", function () {
|
|
status.isUnloading = true;
|
|
});
|
|
var onSocketMessage = {
|
|
hot: function hot() {
|
|
if (parsedResourceQuery.hot === "false") {
|
|
return;
|
|
}
|
|
|
|
options.hot = true;
|
|
},
|
|
liveReload: function liveReload() {
|
|
if (parsedResourceQuery["live-reload"] === "false") {
|
|
return;
|
|
}
|
|
|
|
options.liveReload = true;
|
|
},
|
|
invalid: function invalid() {
|
|
log.info("App updated. Recompiling..."); // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
|
|
|
|
if (options.overlay) {
|
|
hide();
|
|
}
|
|
|
|
sendMessage("Invalid");
|
|
},
|
|
|
|
/**
|
|
* @param {string} hash
|
|
*/
|
|
hash: function hash(_hash) {
|
|
status.previousHash = status.currentHash;
|
|
status.currentHash = _hash;
|
|
},
|
|
logging: setAllLogLevel,
|
|
|
|
/**
|
|
* @param {boolean} value
|
|
*/
|
|
overlay: function overlay(value) {
|
|
if (typeof document === "undefined") {
|
|
return;
|
|
}
|
|
|
|
options.overlay = value;
|
|
},
|
|
|
|
/**
|
|
* @param {number} value
|
|
*/
|
|
reconnect: function reconnect(value) {
|
|
if (parsedResourceQuery.reconnect === "false") {
|
|
return;
|
|
}
|
|
|
|
options.reconnect = value;
|
|
},
|
|
|
|
/**
|
|
* @param {boolean} value
|
|
*/
|
|
progress: function progress(value) {
|
|
options.progress = value;
|
|
},
|
|
|
|
/**
|
|
* @param {{ pluginName?: string, percent: number, msg: string }} data
|
|
*/
|
|
"progress-update": function progressUpdate(data) {
|
|
if (options.progress) {
|
|
log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "").concat(data.percent, "% - ").concat(data.msg, "."));
|
|
}
|
|
|
|
sendMessage("Progress", data);
|
|
},
|
|
"still-ok": function stillOk() {
|
|
log.info("Nothing changed.");
|
|
|
|
if (options.overlay) {
|
|
hide();
|
|
}
|
|
|
|
sendMessage("StillOk");
|
|
},
|
|
ok: function ok() {
|
|
sendMessage("Ok");
|
|
|
|
if (options.overlay) {
|
|
hide();
|
|
}
|
|
|
|
reloadApp(options, status);
|
|
},
|
|
// TODO: remove in v5 in favor of 'static-changed'
|
|
|
|
/**
|
|
* @param {string} file
|
|
*/
|
|
"content-changed": function contentChanged(file) {
|
|
log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
|
|
self.location.reload();
|
|
},
|
|
|
|
/**
|
|
* @param {string} file
|
|
*/
|
|
"static-changed": function staticChanged(file) {
|
|
log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
|
|
self.location.reload();
|
|
},
|
|
|
|
/**
|
|
* @param {Error[]} warnings
|
|
* @param {any} params
|
|
*/
|
|
warnings: function warnings(_warnings, params) {
|
|
log.warn("Warnings while compiling.");
|
|
|
|
var printableWarnings = _warnings.map(function (error) {
|
|
var _formatProblem = formatProblem("warning", error),
|
|
header = _formatProblem.header,
|
|
body = _formatProblem.body;
|
|
|
|
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
});
|
|
|
|
sendMessage("Warnings", printableWarnings);
|
|
|
|
for (var i = 0; i < printableWarnings.length; i++) {
|
|
log.warn(printableWarnings[i]);
|
|
}
|
|
|
|
var needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings;
|
|
|
|
if (needShowOverlayForWarnings) {
|
|
var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
|
|
show("warning", _warnings, trustedTypesPolicyName || null);
|
|
}
|
|
|
|
if (params && params.preventReloading) {
|
|
return;
|
|
}
|
|
|
|
reloadApp(options, status);
|
|
},
|
|
|
|
/**
|
|
* @param {Error[]} errors
|
|
*/
|
|
errors: function errors(_errors) {
|
|
log.error("Errors while compiling. Reload prevented.");
|
|
|
|
var printableErrors = _errors.map(function (error) {
|
|
var _formatProblem2 = formatProblem("error", error),
|
|
header = _formatProblem2.header,
|
|
body = _formatProblem2.body;
|
|
|
|
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
});
|
|
|
|
sendMessage("Errors", printableErrors);
|
|
|
|
for (var i = 0; i < printableErrors.length; i++) {
|
|
log.error(printableErrors[i]);
|
|
}
|
|
|
|
var needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors;
|
|
|
|
if (needShowOverlayForErrors) {
|
|
var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
|
|
show("error", _errors, trustedTypesPolicyName || null);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* @param {Error} error
|
|
*/
|
|
error: function error(_error) {
|
|
log.error(_error);
|
|
},
|
|
close: function close() {
|
|
log.info("Disconnected!");
|
|
|
|
if (options.overlay) {
|
|
hide();
|
|
}
|
|
|
|
sendMessage("Close");
|
|
}
|
|
};
|
|
var socketURL = createSocketURL(parsedResourceQuery);
|
|
socket(socketURL, onSocketMessage, options.reconnect); |