私は本当に私はイントロhereや他のtutorialsの束を読んで、私は、個々の質問を持っているようにそれはそう...私は基本的に2つのファイルを作成することによって、次の例午前、WebPACKの点を理解していませんサイト:Webpackバンドルファイル - それは何ですか?
app.js:
document.write('welcome to my app');
console.log('app loaded');
のindex.html:
<html>
<body>
<script src="bundle.js"></script>
</body>
</html>
それから私は、たまたまバンドルファイルを、作成するために、CLIからwebpack ./app.js bundle.js
を実行します。
そう...はどのようにバンドルファイルは現在、慣れるでしょうか?それは何ですか?私はそれは、本質的にそれをuglifiedその後、単一のファイルに「すべて」をコンパイルして思ったが、それはケースのように思われない、出力に含まの一部は、このようになります(完全な出力を含めるように編集):
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {
document.write('welcome to my app');
console.log('app loaded');
/***/ }
/******/ ]);
だから、何がポイントですか?このバンドルファイルからアプリを実行できますか?バンドルは何とか参照されますか?バンドルを作成した後も元のi ndex.html
とapp.js
ファイルが必要ですか?
あなたの 'webpack.config.js'を表示します。 – haim770
モジュールバンドラはエントリファイルを取得し、すべての依存関係(ファイルがロードする他のファイル/モジュール)を決定し、それらを1つのファイル("バンドル ")に結合します。 –