store url as Buffer to avoid serialization warnings
makes deserialization cheaper
This commit is contained in:
parent
e2d214a1ce
commit
17f317bef2
|
@ -1031,7 +1031,7 @@ class RuntimeTemplate {
|
|||
const codeGen = codeGenerationResults.get(module, runtime);
|
||||
const { data } = codeGen;
|
||||
const url = data.get("url");
|
||||
if (url) return url;
|
||||
if (url) return url.toString();
|
||||
const filename = data.get("filename");
|
||||
return publicPath + filename;
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ class AssetGenerator extends Generator {
|
|||
},${encodedContent}`;
|
||||
}
|
||||
const data = getData();
|
||||
data.set("url", encodedSource);
|
||||
data.set("url", Buffer.from(encodedSource));
|
||||
return new RawSource(
|
||||
`${RuntimeGlobals.module}.exports = ${JSON.stringify(
|
||||
encodedSource
|
||||
|
|
|
@ -33,6 +33,7 @@ class RawDataUrlModule extends Module {
|
|||
constructor(url, identifier, readableIdentifier) {
|
||||
super("asset/raw-data-url", null);
|
||||
this.url = url;
|
||||
this.urlBuffer = url ? Buffer.from(url) : undefined;
|
||||
this.identifierStr = identifier || this.url;
|
||||
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
|
||||
}
|
||||
|
@ -56,6 +57,7 @@ class RawDataUrlModule extends Module {
|
|||
* @returns {number} the estimated size of the module (must be non-zero)
|
||||
*/
|
||||
size(type) {
|
||||
if (this.url === undefined) this.url = this.urlBuffer.toString();
|
||||
return Math.max(1, this.url.length);
|
||||
}
|
||||
|
||||
|
@ -97,13 +99,14 @@ class RawDataUrlModule extends Module {
|
|||
* @returns {CodeGenerationResult} result
|
||||
*/
|
||||
codeGeneration(context) {
|
||||
if (this.url === undefined) this.url = this.urlBuffer.toString();
|
||||
const sources = new Map();
|
||||
sources.set(
|
||||
"javascript",
|
||||
new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
|
||||
);
|
||||
const data = new Map();
|
||||
data.set("url", this.url);
|
||||
data.set("url", this.urlBuffer);
|
||||
const runtimeRequirements = new Set();
|
||||
runtimeRequirements.add(RuntimeGlobals.module);
|
||||
return { sources, runtimeRequirements, data };
|
||||
|
@ -115,14 +118,14 @@ class RawDataUrlModule extends Module {
|
|||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {
|
||||
hash.update(this.url);
|
||||
hash.update(this.urlBuffer);
|
||||
super.updateHash(hash, context);
|
||||
}
|
||||
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
|
||||
write(this.url);
|
||||
write(this.urlBuffer);
|
||||
write(this.identifierStr);
|
||||
write(this.readableIdentifierStr);
|
||||
|
||||
|
@ -132,7 +135,7 @@ class RawDataUrlModule extends Module {
|
|||
deserialize(context) {
|
||||
const { read } = context;
|
||||
|
||||
this.url = read();
|
||||
this.urlBuffer = read();
|
||||
this.identifierStr = read();
|
||||
this.readableIdentifierStr = read();
|
||||
|
||||
|
|
Loading…
Reference in New Issue