emitFileの製造方法
emitFile(){ // 打包输出的路径 主せ= path.join(この .config.output.path、この.config.output.filename) にconsole.log(メイン、' テスト' ) この .assets = {} / / templateStr =ましょう。この .getSource(path.join(__ dirnameのを、' main.ejs ' )); コードせ({:エントリId templateStr、= ejs.render この .entryIdは、モジュール:この.modulesを}) // 路径对应的代码 この .assets [メイン] = コード。 fs.writeFileSync(メイン、この.assets [メイン]) }
-
出力パスと出力名ステッチ一緒にパッケージ化された出力パス
-
オブジェクトを宣言
-
main.ejsを作成します
最初
のコマンドを実行します。NPM私EJS-Dビンに再作成した
main.ejs
(機能(モジュール){ VAR installedModules = {}; 関数__webpack_require __(モジュールID){ IF(installedModules [モジュールID]){ 戻りinstalledModules [モジュールID]の.exports; } VARモジュール= installedModules [モジュールID] = { I:モジュールID、 L:偽、 輸出:{} }; モジュール[モジュールID]は.call(module.exportsは、モジュール、module.exportsは、__webpack_require__); module.l = TRUE; 戻りmodule.exportsは; } 戻り__webpack_require __(__ webpack_require __ S =「<%。 -entryId%> "); }) / *自执行函数传入参数* / ({ (モジュールでキーを聞かせ){%>のための<% "<% -キー%>" (機能(モジュール、輸出、__webpack_require__ ){ 評価( `<% -モジュール[キー]%>`)。 })、 <%}%> });
-
ejs.render方法によって生成され、最終的なパッケージファイル
-
fs.readFileSyncは()出力ファイルbundle.jsパスに書き込まれます。
vocodeに実行コードで実行オープンDIST / bundle.js WebPACKの-devの
出力:
こんにちはA2020
手書きのWebPACKの成功の私達の簡単な証拠バージョン
注:https://app.yinxiang.com/fx/83b8b85b-c3c9-4bc2-8881-da5dc3f99947