@@ -130,7 +130,7 @@ function createESMSourcesAndResources2(options) {
130130 write ( getDestAbsoluteFilePath ( file ) , JSON . stringify ( tsConfig , null , '\t' ) ) ;
131131 continue ;
132132 }
133- if ( / \. d \. t s $ / . test ( file ) || / \. c s s $ / . test ( file ) || / \. j s $ / . test ( file ) ) {
133+ if ( / \. d \. t s $ / . test ( file ) || / \. c s s $ / . test ( file ) || / \. j s $ / . test ( file ) || / \. t t f $ / . test ( file ) ) {
134134 // Transport the files directly
135135 write ( getDestAbsoluteFilePath ( file ) , fs . readFileSync ( path . join ( SRC_FOLDER , file ) ) ) ;
136136 continue ;
@@ -250,35 +250,37 @@ function transportCSS(module, enqueue, write) {
250250 const filename = path . join ( SRC_DIR , module ) ;
251251 const fileContents = fs . readFileSync ( filename ) . toString ( ) ;
252252 const inlineResources = 'base64' ; // see https://github.com/Microsoft/monaco-editor/issues/148
253- const inlineResourcesLimit = 300000 ; //3000; // see https://github.com/Microsoft/monaco-editor/issues/336
254- const newContents = _rewriteOrInlineUrls ( fileContents , inlineResources === 'base64' , inlineResourcesLimit ) ;
253+ const newContents = _rewriteOrInlineUrls ( fileContents , inlineResources === 'base64' ) ;
255254 write ( module , newContents ) ;
256255 return true ;
257- function _rewriteOrInlineUrls ( contents , forceBase64 , inlineByteLimit ) {
256+ function _rewriteOrInlineUrls ( contents , forceBase64 ) {
258257 return _replaceURL ( contents , ( url ) => {
259- let imagePath = path . join ( path . dirname ( module ) , url ) ;
260- let fileContents = fs . readFileSync ( path . join ( SRC_DIR , imagePath ) ) ;
261- if ( fileContents . length < inlineByteLimit ) {
262- const MIME = / \. s v g $ / . test ( url ) ? 'image/svg+xml' : 'image/png' ;
263- let DATA = ';base64,' + fileContents . toString ( 'base64' ) ;
264- if ( ! forceBase64 && / \. s v g $ / . test ( url ) ) {
265- // .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
266- let newText = fileContents . toString ( )
267- . replace ( / " / g, '\'' )
268- . replace ( / < / g, '%3C' )
269- . replace ( / > / g, '%3E' )
270- . replace ( / & / g, '%26' )
271- . replace ( / # / g, '%23' )
272- . replace ( / \s + / g, ' ' ) ;
273- let encodedData = ',' + newText ;
274- if ( encodedData . length < DATA . length ) {
275- DATA = encodedData ;
276- }
258+ const fontMatch = url . match ( / ^ ( .* ) .t t f \? ( .* ) $ / ) ;
259+ if ( fontMatch ) {
260+ const relativeFontPath = `${ fontMatch [ 1 ] } .ttf` ; // trim the query parameter
261+ const fontPath = path . join ( path . dirname ( module ) , relativeFontPath ) ;
262+ enqueue ( fontPath ) ;
263+ return relativeFontPath ;
264+ }
265+ const imagePath = path . join ( path . dirname ( module ) , url ) ;
266+ const fileContents = fs . readFileSync ( path . join ( SRC_DIR , imagePath ) ) ;
267+ const MIME = / \. s v g $ / . test ( url ) ? 'image/svg+xml' : 'image/png' ;
268+ let DATA = ';base64,' + fileContents . toString ( 'base64' ) ;
269+ if ( ! forceBase64 && / \. s v g $ / . test ( url ) ) {
270+ // .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
271+ let newText = fileContents . toString ( )
272+ . replace ( / " / g, '\'' )
273+ . replace ( / < / g, '%3C' )
274+ . replace ( / > / g, '%3E' )
275+ . replace ( / & / g, '%26' )
276+ . replace ( / # / g, '%23' )
277+ . replace ( / \s + / g, ' ' ) ;
278+ let encodedData = ',' + newText ;
279+ if ( encodedData . length < DATA . length ) {
280+ DATA = encodedData ;
277281 }
278- return '"data:' + MIME + DATA + '"' ;
279282 }
280- enqueue ( imagePath ) ;
281- return url ;
283+ return '"data:' + MIME + DATA + '"' ;
282284 } ) ;
283285 }
284286 function _replaceURL ( contents , replacer ) {
0 commit comments