@@ -33,6 +33,7 @@ class RawDataUrlModule extends Module {
33
33
constructor ( url , identifier , readableIdentifier ) {
34
34
super ( "asset/raw-data-url" , null ) ;
35
35
this . url = url ;
36
+ this . urlBuffer = url ? Buffer . from ( url ) : undefined ;
36
37
this . identifierStr = identifier || this . url ;
37
38
this . readableIdentifierStr = readableIdentifier || this . identifierStr ;
38
39
}
@@ -56,6 +57,7 @@ class RawDataUrlModule extends Module {
56
57
* @returns {number } the estimated size of the module (must be non-zero)
57
58
*/
58
59
size ( type ) {
60
+ if ( this . url === undefined ) this . url = this . urlBuffer . toString ( ) ;
59
61
return Math . max ( 1 , this . url . length ) ;
60
62
}
61
63
@@ -97,13 +99,14 @@ class RawDataUrlModule extends Module {
97
99
* @returns {CodeGenerationResult } result
98
100
*/
99
101
codeGeneration ( context ) {
102
+ if ( this . url === undefined ) this . url = this . urlBuffer . toString ( ) ;
100
103
const sources = new Map ( ) ;
101
104
sources . set (
102
105
"javascript" ,
103
106
new RawSource ( `module.exports = ${ JSON . stringify ( this . url ) } ;` )
104
107
) ;
105
108
const data = new Map ( ) ;
106
- data . set ( "url" , this . url ) ;
109
+ data . set ( "url" , this . urlBuffer ) ;
107
110
const runtimeRequirements = new Set ( ) ;
108
111
runtimeRequirements . add ( RuntimeGlobals . module ) ;
109
112
return { sources, runtimeRequirements, data } ;
@@ -115,14 +118,14 @@ class RawDataUrlModule extends Module {
115
118
* @returns {void }
116
119
*/
117
120
updateHash ( hash , context ) {
118
- hash . update ( this . url ) ;
121
+ hash . update ( this . urlBuffer ) ;
119
122
super . updateHash ( hash , context ) ;
120
123
}
121
124
122
125
serialize ( context ) {
123
126
const { write } = context ;
124
127
125
- write ( this . url ) ;
128
+ write ( this . urlBuffer ) ;
126
129
write ( this . identifierStr ) ;
127
130
write ( this . readableIdentifierStr ) ;
128
131
@@ -132,7 +135,7 @@ class RawDataUrlModule extends Module {
132
135
deserialize ( context ) {
133
136
const { read } = context ;
134
137
135
- this . url = read ( ) ;
138
+ this . urlBuffer = read ( ) ;
136
139
this . identifierStr = read ( ) ;
137
140
this . readableIdentifierStr = read ( ) ;
138
141
0 commit comments