




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
Webpack-手寫一個bundle.jsgnbtwtgaiaconsole.log("hellomodule.exports={console.log(source,this,this.query);returnconstpath=require('path')module:{rules:test:use:path.resolve(dirname,loader-module:{rules:test:/\.js$/,use:[loader:path.resolve(dirname,"./loader/replaceLoader.js"),options:{name:"開課吧//constloaderUtilsrequire("loader-utils");//官方推薦處理loader,querymodule.exports=function(source)//returnsource.replace("kkb",);constoptions=loaderUtils.getOptions(this);constresult=source.replace("kkb",returnsource.replace("kkb",constloaderUtilsrequire("loader-utils");//官方推薦處理loader,querymodule.exports=function(source)constoptions=constresult=source.replace("kkb",);this.callback(null,result);err:Error|null,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-module.exports=function(source)constoptions=//callback就是this.callback注意參數(shù)的使用constcallback=this.async();setTimeout(()=>{constresult=source.replace("kkb",);callback(null,result);},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:test:/\.js$/,use:[path.resolve(dirname,loader:path.resolve(dirname,"./loader/replaceLoaderAsync.js"),options:{name:"開課吧//use:[path.resolve(dirname,resolveLoaderresolveLoader:modules:["node_modules",{rules:test:/\.js$/,use:[loader:"replaceLoaderAsync",options:{name:"開課吧//use:[path.resolve(dirname,:classclassCopyrightWebpackPluginconstructor()apply(compiler)module.exports=constconstCopyrightWebpackPlugin=require("./plugin/copyright-webpack-plugins:[newplugins:[CopyrightWebpackPlugin({ame"開課吧classCopyrightWebpackPlugin{constructor(options)apply(compiler)module.exports=classclassCopyrightWebpackPlugin{constructor(options){//apply(compiler)//hooks.emit(compilation,cb)=>{{source:function(){return"hellosize:{return//pile.tap("CopyrightWebpackPlugin",compilation=>//console.log("開始了module.exports="debug":"node--inspect--inspect-webpackwebpack在執(zhí)行npxwebpack((function(modules)varinstalledModules=functionwebpack_require{if(installedModules[moduleId])returnreturnvarmodule=(installedModules[moduleId]{i:moduleId,l:false,exports:{}module.l=true;returnmodule.exports;returnwebpack_require((webpack_require.s="./index.js":function(module,{'//importafrom"./a";\n\nconsole.log("helloword");\n\n\n//#constconstfs=constfenximokuai=filename=>constcontent=fs.readFileSync(filename,"utf-8");我們推薦使用ab/paser,這是7的工具,來幫助我們分析內(nèi)部的語法,包括e6,返回astnpminstall@babel/parser--constfs=constparser=constfenximokuai=filename=>constcontent=fs.readFileSync(filename,"utf-constAst=parser.parse(content,{sourceType:"module"constconstfs=require("fs");constpath=require("path");constparser=consttraverse=constfenximokuai=filename=>constcontent=fs.readFileSync(filename,"utf-constAst=parser.parse(content,{sourceType:"module"constdependencies=traverse(Ast,{ImportDeclaration({node{constparser=//修改dependenciesconstdependencies=constnewfilename="./"+path.join(path.dirname(filename),dependencies[node.source.valuenewfilename;constconstbabel=const{code}=babel.transformFromAst(Ast,null,{presets:["@babel/preset-env"]returnreturnconstconstfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');constmoduleAnalyser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=constnewFile='./'+path.join(dirname,node.source.value);dependencies[node.source.value]=newFile;const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-{constconstmoduleInfo=moduleAnalyser('./src/index.js');constfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');constmoduleAnalyser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=constnewFile='./'+path.join(dirname,node.source.value);dependencies[node.source.value]=newFile;}const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-{filename,}}constmakeDependenciesGraph=(entry){constentryModule=moduleAnalyser(entry);constgraphArray=[entryModule];for(leti=0;i<graphArray.length;{constitem=constconst{dependencies}=item;if(dependencies){for(letjin{graphArray.push(constgraph={};graphArray.forEach(item=>{graph[item.filename]{dependencies:item.dependencies,code:item.codereturnconstgraghInfo=constfs=require('fs');constpath=require('path');constparser=consttraverse=require('@babel/traverse').default;constbabel=require('@babel/core');constmoduleAnalyser=(filename)=>constcontent=fs.readFileSync(filename,'utf-8');constast=parser.parse(content,{sourceType:constdependencies={};traverse(ast,{ImportDeclaration({node})constdirname=constnewFile='./'+path.join(dirname,node.source.value);dependencies[node.source.value]=newFile;const{code}=babel.transformFromAst(ast,{presets:["@babel/preset-return}}constmakeDependenciesGraph=(entry){constentryModule=module
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 民宿短租平臺用戶入住及退房流程管理協(xié)議
- 國際法律顧問團(tuán)隊(duì)派遣服務(wù)協(xié)議
- 專業(yè)美容美發(fā)技術(shù)培訓(xùn)與創(chuàng)業(yè)支持合同
- 互聯(lián)網(wǎng)支付貨幣合規(guī)管理補(bǔ)充協(xié)議
- 藝術(shù)展覽館運(yùn)營與管理委托合同
- 俄羅斯能源輸送管道監(jiān)理與維護(hù)補(bǔ)充協(xié)議
- 電力設(shè)施租賃補(bǔ)充協(xié)議(儲能電站建設(shè))
- 房產(chǎn)抵押貸款與互聯(lián)網(wǎng)金融創(chuàng)新服務(wù)合同
- 快餐連鎖品牌加盟及綠色有機(jī)食材供應(yīng)協(xié)議
- 倉庫租賃補(bǔ)充協(xié)議(含消防)
- 2025年鄉(xiāng)村振興戰(zhàn)略相關(guān)考試試題及答案
- 2024-2025學(xué)年全國版圖知識競賽(小學(xué)組)考試題庫(含答案)
- JJF1033-2023計(jì)量標(biāo)準(zhǔn)考核規(guī)范
- MOOC 營銷管理-電子科技大學(xué) 中國大學(xué)慕課答案
- 揚(yáng)塵污染專項(xiàng)防治方案
- GB 5009.34-2022食品安全國家標(biāo)準(zhǔn)食品中二氧化硫的測定
- GB/T 12622-2008管法蘭用墊片壓縮率和回彈率試驗(yàn)方法
- 語文五年級 【知識精講】7.閱讀(2)文言文閱讀
- 社會心理學(xué)8-人際關(guān)系課件
- QC-R 596-2017高速鐵路板式無砟軌道自密實(shí)混凝土高清-無水印
- 2023高中學(xué)業(yè)水平合格性考試歷史重點(diǎn)知識點(diǎn)歸納總結(jié)(復(fù)習(xí)必背)
評論
0/150
提交評論