FS = LET( 'FS')が必要です。 必要とパス=( 'パス')せを、 バビロン=( 'バビロン')を必要とせ; ASTバビロンにソースを変換する// Tは( 'バベル/タイプ@')が必要です= LET ; // @バベル・タイプの交換ノードが トラバース=は( '@のバベル必要とせ /トラバース')デフォルト;. // @バベル-トラバースノードトラバーサル LETジェネレータ=必要とする( '@のバベル /ジェネレータ')デフォルト;. // @ バベル/ジェネレータ生成 EJSの=は、( 'EJS'を必要とせ ); // JS テンプレート・ クラス・コンパイラ{ //コンストラクタ コンストラクタ(設定){ //エントリOUT this.config = configの、 保存する// 1、ファイルの入口経路。 これを.entryId; // 2、モジュールのすべての依存関係ボア村 this.modules = {}; //導入路 this.entry = config.entry。 //現用パス LET moduleNameのnode.arguments = [0] .Valueの; //モジュール名への参照を取得しています = process.cwd this.root(); } //ファイルソース取得 メソッドgetSource(のModulePathを){ fs.readFileSync含量=(のModulePath、 'UTF8')させ; 、コンテンツを返す } //解析ソースコード {解析(ソース、parentPath) // AST構文解析ツリー のlet AST = babylon.parse(ソース); LET依存性= []; トラバース(AST、{ CallExpression(P){ LETノード= p.node; //対応するノード node.callee(もし。 ===名'必要'){ node.callee.name = '__webpack_require__'; moduleNameの= moduleNameの+(?。path.extname(moduleNameの) ''」JS'); moduleNameの=」./'+path.join(parentPath,moduleName)。 dependencies.push(moduleNameの)。 node.arguments = [t.stringLiteral(moduleNameの)]。 } } })。 ソースコードは、=ジェネレータ(AST).CODEましょう。 リターン{ソースコード、依存性} } //建立模块 buildModule(のModulePath、isEntry){ //拿到模块的内容 せソース= this.getSource(のModulePath)。 //模块IDのModulePathのModulePath-this.root = SRC / index.js せmoduleNameの=」./'+path.relative(this。ルート、のModulePath); IF(isEntry){ //エントリ名を保存 this.entryId = moduleNameの; } //解析ソースコードを変換する必要があるソース、依存関係のリストを返すには 、{ソースコード、依存関係を}せthis.parse =(出典、path.dirname(moduleNameの)); this.modules [moduleNameの] =ソースコード; dependencies.forEach( //親モジュールのロードを再帰的にロードする (DEP)=> { this.buildModule(path.join (this.root、DEP)、偽に) } ); } emitFile(){ //ファイル送信 //データレンダリング //出力経路が 主= path.join(this.config.output.path、this.configましょう 。 output.filename); @テンプレートパス LET tempateStr = this.getSource(path.join(__ DIRNAME、 'main.ejs')); LETコード= ejs.render(tempateStr、{ エントリId:this.entryId、 モジュール:this.modules }); // this.assetsの= {}; // //パスコード対応する [メイン] =コード// this.assetsを; // fs.writeFileSync(メイン、this.assets [メイン]); fs.writeFileSync(メイン、コード); } RUN(){ //実行そして作成モジュールの依存関係 this.buildModule(path.resolve(this.root、this.entry) 、TRUE); ファイル//送信した後に充填 this.emitFileを(); } } module.exportsは=コンパイラ。