




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
Wck- wck在執行npxwck進行打包后,都干了什么事情((function(modules)varinstalledModules=functionck_require{if(installedModules[moduleId])return}varmodule=(installedModules[moduleId]{i:moduleId,l:false,exports:{}wwmodule.l=true;} ck_require((ck_require.s"./index.js":function(module,{'//importafrom"./a";\n\nconsole.log(" word");\n\n\n//#sourceURL=w "./a.js":function(module,{'//importafrom"./a";\n\nconsole.log(" word");\n\n\n//#sourceURL=w "./b.js":function(module,{'//importafrom"./a";\n\nconsole.log(" word");\n\n\n//#sourceURL=w }大概的意思就是,我們實現了一個wck_require來實現自己的模塊wck配置文出創建一個wck哪些內容:wck啟動函自己實現一個模塊分析:文件,分析代constfs=constconstfenximokuai=filename=>constcontent=fs.readFileSync(filename,"utf-8"); npminstallnpminstall@babel/parser--constfs=constparser=constfenximokuai=filename=>constcontent=fs.readFileSync(filename,"utf-constAst={sourceType:npminstall@babel/traverse--constconstfs=require("fs");constpath=require("path");constparser=consttraverse=constfenximokuai=filename=>constconstcontent=fs.readFileSync(filename,"utf-constAst={sourceType:constdependencies=traverse(Ast,{ImportDeclaration({node{console.log(node);}文件引入的模塊引入路在項目中里的可以在瀏覽?里執行的處理現在的路徑問constparser=//修改dependenciesconstdependencies=constnewfilename="./"+path.join(path.dirname(filename),dependencies[node.source.valuenewfilename;把代碼處理成瀏覽?可運行的代碼,需要借助@babel/core@babel/preset-env,把ast語法樹轉換成合適的constbabel=const{code}=babel.transformFromAst(Ast,{presets:["@babel/preset-導出所有分析出的returnreturn完成代碼constfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');const yser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=path.dirname(filename);constnewFile='./'+path.join(dirname,dependencies[node.source.value]=}const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-{filename,}constconstmoduleInfo=}分析依塊的分析:constfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');const yser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=path.dirname(filename);constnewFile='./'+path.join(dirname,dependencies[node.source.value]=}const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-{filename,}}constmakeDependenciesGraph=(entry){constentryModule=module constgraphArray=[entryModule];for(leti=0;i<graphArray.length;{constitem=graphArray[i];const{dependencies}=item;if(dependencies){for(letjin{ }}}constgraph={};graphArray.forEach(item=>{graph[item.filename]{dependencies:item.dependencies,code:item.code}return}constgraghInfo=makeDependenciesGraph('./src/index.js');生成代constfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');const yser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=path.dirname(filename);constnewFile='./'+path.join(dirname,dependencies[node.source.value]=}const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-{filename,}}constmakeDependenciesGraph=(entry){constentryModule=module constgraphArray=[entryModule];for(leti=0;i<graphArray.length;{constitem=graphArray[i];const{dependencies}=item;if(dependencies){for(letjin{ }}}constgraph={};graphArray.forEach(item=>{graph[item.filename]{dependencies:item.dependencies,code:item.code}return}constgenerateCode=(entry)=>constgraph=JSON.stringify(makeDependenciesGraph(entry));return`functionrequire(module)function{return}varexports={};(function(require,exports,code){})(localRequire,exports,graph[module].code);returnexports;}constconstcode=generateCode('./src/index.js');"debug":"node--inspect--inspect- 如何自己編寫一個接口文檔 創建一個替換源碼中字符串的omodule.exports=console.log(source,this,this.query);returnsource.replace('kkb','開課吧') 在配置文件中使用constpath=require('path')module:{rules:{test:use:path.resolve(dirname,}] module:rules:{test:/\.js$/,use:[{loader:path.resolve(dirname,name:開課}}]}]//constloaderUtilsrequire("loader- module.exports=function(source)//returnsource.replace("kkb",);constoptions=loaderUtils.getOptions(this);constresult=source.replace("kkb",);returnsource.replace("kkb",);}this.callback:如何返回多個信息,不止是處理好的源碼呢,可以使用constconstloaderUtilsrequire("loader- module.exports=function(source)constoptions=loaderUtils.getOptions(this);constresult=source.replace("kkb",);this.callback(null,result);:Error|content:string|Buffer,sourceMap?:SourceMap,meta?:anyconstconstloaderUtils=require("loader-module.exports=function(source)constoptions=loaderUtils.getOptions(this);setTimeout(()=>{constresult=source.replace("kkb",return},我們使 constconstloaderUtils=require("loader-//callback就是this.callbackconstcallback=this.async();setTimeout(()=>{constresult=source.replace("kkb",);callback(null,result);},module.exports=function(source)constoptions=module.exports=returnsource.replace("開課吧",constloaderUtils=require("loader-utils");module.exports=function(source){constoptions= constcallback=this.async();setTimeout(()=>{constresult=source.replace("kkb",);callback(null,result);}, module:{rules:{use:[path.resolve(dirname,{loader:path.resolve(dirname,name:開課}}]//use:[path.resolve(dirname,}]順序,自下而上,自右resolveLoader:modules:["node_modules",{rules:{test:/\.js$/,use:[{loader:"
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 眼鏡連鎖經營模式考核試卷
- 聚丙烯纖維的工藝改進和市場規模考核試卷
- 環保課件小學
- 礦石性質與錫礦物學考核試卷
- 2025年弱粘煤項目發展計劃
- 2025年直流傳動礦井提升機項目發展計劃
- 2019-2025年教師資格之中學地理學科知識與教學能力題庫與答案
- 2019-2025年注冊環保工程師之注冊環保工程師專業基礎每日一練試卷B卷含答案
- 2019-2025年房地產經紀人之房地產交易制度政策綜合檢測試卷A卷含答案
- 2025年風電鑄件項目發展計劃
- 銷售人員試用期考核表
- 工傷職工舊傷復發確認鑒定申請表-模板
- 接觸網完整版本
- 2025年勞務合同模板電子版簡短一點
- 第二講中國經濟行穩致遠-2025年春季學期 形勢與政策課件
- 綠色低碳轉型戰略背景下綠色會展可持續發展研究
- LY/T 2071-2024人造板類產品生產綜合能耗
- 統編版語文一年級下冊2024-2025學年度語文園地五(課件)
- 病房心臟驟停應急演練
- 2024-2030年中國橡塑防滑墊市場競爭格局與前景發展策略分析報告
- 家具的類型(分類全面)-課件
評論
0/150
提交評論