




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
Wck- wck在執(zhí)行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 }大概的意思就是,我們實現(xiàn)了一個wck_require來實現(xiàn)自己的模塊wck配置文出創(chuàng)建一個wck哪些內(nèi)容:wck啟動函自己實現(xiàn)一個模塊分析:文件,分析代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);}文件引入的模塊引入路在項目中里的可以在瀏覽?里執(zhí)行的處理現(xiàn)在的路徑問constparser=//修改dependenciesconstdependencies=constnewfilename="./"+path.join(path.dirname(filename),dependencies[node.source.valuenewfilename;把代碼處理成瀏覽?可運行的代碼,需要借助@babel/core@babel/preset-env,把ast語法樹轉(zhuǎn)換成合適的constbabel=const{code}=babel.transformFromAst(Ast,{presets:["@babel/preset-導(dǎo)出所有分析出的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- 如何自己編寫一個接口文檔 創(chuàng)建一個替換源碼中字符串的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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年大學(xué)試題(教育學(xué))-教育學(xué)原理歷年參考題庫含答案解析(5套典型考題)
- 2025年大學(xué)試題(大學(xué)選修課)-沙盤游戲與心靈對話歷年參考題庫含答案解析(5套典型考題)
- 2025年大學(xué)試題(哲學(xué))-中國哲學(xué)史歷年參考題庫含答案解析(5套典型考題)
- 2025年大學(xué)試題(醫(yī)學(xué))-生物制藥工藝學(xué)歷年參考題庫含答案解析(5套典型考題)
- 2025年大學(xué)試題(醫(yī)學(xué))-中草藥知識歷年參考題庫含答案解析(5套典型考題)
- 2025年國家開放大學(xué)(電大)-計算機信息管理(???歷年參考題庫含答案解析(5套典型考題)
- 2025年衛(wèi)生資格(中初級)-職業(yè)病主治醫(yī)師歷年參考題庫含答案解析(5套典型題)
- 2025年衛(wèi)生知識健康教育知識競賽-突發(fā)急性傳染病知識競賽歷年參考題庫含答案解析(5套典型考題)
- 2025年醫(yī)藥衛(wèi)生考試-公共衛(wèi)生知識考試歷年參考題庫含答案解析(5套典型題)
- 2025年醫(yī)學(xué)繼續(xù)教育-社區(qū)護理學(xué)繼續(xù)教育歷年參考題庫含答案解析(5套典型考題)
- 高中生物課標(biāo)教材解析(全)課件
- 公司法人代持協(xié)議
- JJG 814-2015自動電位滴定儀
- JJF 1753-2019醫(yī)用體外壓力脈沖碎石機校準(zhǔn)規(guī)范
- GB/T 9385-2008計算機軟件需求規(guī)格說明規(guī)范
- TWEEA 006-2022 中小學(xué)校教室照明技術(shù)規(guī)范
- GB/T 17874-2021電子特氣三氯化硼
- GB/T 13384-2008機電產(chǎn)品包裝通用技術(shù)條件
- 雨季(汛期)施工安全教育培訓(xùn)
- DB32-T 2860-2015散裝液體化學(xué)品槽車裝卸安全作業(yè)規(guī)范-(高清現(xiàn)行)
- T∕CAQ 10108-2018 供應(yīng)商審核指南
評論
0/150
提交評論