This repository was archived by the owner on Sep 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +18
-1
lines changed Expand file tree Collapse file tree 6 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ const loader = {
122122 }
123123 else {
124124 let needExports = [ ] ;
125+ if ( opt . preprocess ) {
126+ code = opt . preprocess ( code , path ) ;
127+ }
125128 code = this . removeComment ( code ) ;
126129 let strict = '' ;
127130 if ( code . includes ( '"use strict"' ) ) {
Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ loader.ready(function () {
104104 alert ( 'The invoke function.' ) ;
105105 } ,
106106 'location' : 'The override var.'
107+ } ,
108+ 'preprocess' : function ( code , path ) {
109+ console . log ( `Replace file "${ path } " content.` ) ;
110+ return code . replace ( 'nothing' , 'none' ) ;
107111 }
108112 } ) [ 0 ] ;
109113 ( _a = document . getElementById ( 'clear' ) ) === null || _a === void 0 ? void 0 : _a . addEventListener ( 'click' , function ( ) {
Original file line number Diff line number Diff line change 11{
22 "name" : " @litert/loader" ,
3- "version" : " 2.1.2-rc3 " ,
3+ "version" : " 2.1.3-rc4 " ,
44 "description" : " Simple browser module loader." ,
55 "keywords" : [
66 " litert" ,
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ const loader: ILoader = {
6161 'dir' ?: string ;
6262 'style' ?: string ;
6363 'invoke' ?: Record < string , any > ;
64+ 'preprocess' ?: ( code : string , path : string ) => string ;
6465 } = { } ) : any [ ] {
6566 if ( typeof paths === 'string' ) {
6667 paths = [ paths ] ;
@@ -140,6 +141,10 @@ const loader: ILoader = {
140141 else {
141142 /** --- 代码末尾增加 exports.xxx = --- */
142143 let needExports : string [ ] = [ ] ;
144+ // --- 预处理代码 ---
145+ if ( opt . preprocess ) {
146+ code = opt . preprocess ( code , path ) ;
147+ }
143148 // --- 去除 // 注释、/* 注释 ---
144149 code = this . removeComment ( code ) ;
145150 // --- 先去除严格模式字符串 ---
Original file line number Diff line number Diff line change @@ -99,6 +99,10 @@ loader.ready(async function(): Promise<void> {
9999 alert ( 'The invoke function.' ) ;
100100 } ,
101101 'location' : 'The override var.'
102+ } ,
103+ 'preprocess' : function ( code : string , path : string ) : string {
104+ console . log ( `Replace file "${ path } " content.` ) ;
105+ return code . replace ( 'nothing' , 'none' ) ;
102106 }
103107 } ) [ 0 ] ;
104108
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ interface ILoader {
2626 'dir' ?: string ;
2727 'style' ?: string ;
2828 'invoke' ?: Record < string , any > ;
29+ 'preprocess' ?: ( code : string , path : string ) => string ;
2930 } ) : any [ ] ;
3031 /**
3132 * --- 简单 fetch 获取网络数据 ---
You can’t perform that action at this time.
0 commit comments