版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医疗行业中的家居智能技术应用案例分享
- 专属2024版婚礼主持与现场布置一体化服务协议版
- 二零二五年度高层建筑消防通道改造施工协议3篇
- 2025年度个人二手房交易合同模板产权清晰保障版2篇
- 二零二五年度电子商务平台软件开发框架合作协议3篇
- 牡丹江2025年黑龙江牡丹江医学院科大学招聘93人笔试历年参考题库附带答案详解
- 二零二五年度车辆保养与绿色出行奖励合同4篇
- 2025版智慧社区门卫服务与物业管理合同2篇
- 湖北2025年湖北省水利水电科学研究院招聘14人笔试历年参考题库附带答案详解
- 温州2025年浙江温州市公安局洞头区分局第一期招聘编外用工笔试历年参考题库附带答案详解
- 2023年译林版英语五年级下册Units-1-2单元测试卷-含答案
- Unit-3-Reading-and-thinking课文详解课件-高中英语人教版必修第二册
- 施工管理中的文档管理方法与要求
- DL∕T 547-2020 电力系统光纤通信运行管理规程
- 种子轮投资协议
- 物业客服培训课件PPT模板
- 员工工资条模板
- 执行依据主文范文(通用4篇)
- 浙教版七年级数学下册全册课件
- 华为携手深圳国际会展中心创建世界一流展馆
- 2023版思想道德与法治专题2 领悟人生真谛 把握人生方向 第3讲 创造有意义的人生
评论
0/150
提交评论