版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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注意参数的使用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在执行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的工具,来帮助我们分析内部的语法,包括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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 社区消防安全目标管理
- 宝宝按摩促进发育
- 黄疸患者的体温护理监测
- 胃切除术后营养补充策略
- 护理人文关怀的社会意义
- 护理人文关怀:传递温暖与希望
- 管道护理与健康教育
- 护理敏感指标的数据收集方法
- 姜宸英:清初文化脉络中的多面文人与时代镜像
- 妊娠期高血压疾病发病机理及临床结局的深度剖析-基于194例临床病例的综合研究
- 2024版体育赛事赞助对赌协议合同范本3篇
- 《现代秘书思维》课件-现代秘书思维的应用与提升
- 安全生产责任保险事故预防技术服务评估考评评分细则
- 小学一年级下册数学-期末乐考
- 2024版商品混凝土委托加工合同书范本
- DL5190.4-2019电力建设施工技术规范第4部分:热工仪表及控制装置
- 大气道狭窄护理课件
- 2024年江苏省海洋知识竞赛备考试题库(含答案)
- 晋中学院机械设计制造及其自动化专业大一2018-2019学年机械制图与计算机绘图模拟题
- DF6205电能量采集装置用户手册-2
- 万科集团财务管理制度手册
评论
0/150
提交评论