admin管理员组文章数量:1414852
I really don't understand the point of WebPack, I read an intro here and a bunch of other tutorials, but it seems like I have to ask individual questions... I am following an example by creating 2 files of a basic site:
app.js:
document.write('wele to my app');
console.log('app loaded');
index.html:
<html>
<body>
<script src="bundle.js"></script>
</body>
</html>
Then I run webpack ./app.js bundle.js
from the CLI to create the bundle file, which happens.
So...how does the bundle file get used now? What is it? I thought it essentially piled "everything" into a single file and then uglified it, but that doesn't seem to be the case, some of the ouput looks like this (edited to include full output):
/******/ (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('wele to my app');
console.log('app loaded');
/***/ }
/******/ ]);
So, what's the point? Can the app run from this bundle file? Does the bundle get referenced somehow? Do I still need the original index.html
and app.js
files once the bundle is built?
I really don't understand the point of WebPack, I read an intro here and a bunch of other tutorials, but it seems like I have to ask individual questions... I am following an example by creating 2 files of a basic site:
app.js:
document.write('wele to my app');
console.log('app loaded');
index.html:
<html>
<body>
<script src="bundle.js"></script>
</body>
</html>
Then I run webpack ./app.js bundle.js
from the CLI to create the bundle file, which happens.
So...how does the bundle file get used now? What is it? I thought it essentially piled "everything" into a single file and then uglified it, but that doesn't seem to be the case, some of the ouput looks like this (edited to include full output):
/******/ (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('wele to my app');
console.log('app loaded');
/***/ }
/******/ ]);
So, what's the point? Can the app run from this bundle file? Does the bundle get referenced somehow? Do I still need the original index.html
and app.js
files once the bundle is built?
-
Show your
webpack.config.js
– haim770 Commented Jan 3, 2017 at 19:28 - A module bundler takes an entry file, determines all of its dependencies (i.e. other files/modules the file loads) and bines them into one single file (the "bundle"). – Felix Kling Commented Jan 3, 2017 at 19:32
1 Answer
Reset to default 7I'm the author of the first article you linked. A "bundled" file just means all the Javascript your app/website needs to run, piled into one file the browser can understand. For example, in your source code you might use require()
or import
statements. The browser has no idea how to execute those, so Webpack will pile all of your Javascript code into a "bundled" file that the browser can understand and execute without error.
Webpack doesn't minify code by default, you have to use the uglify plugin.
You do not need the original source code, just the output built Javascript file by Webpack. You need to set up your HTML to read the bundled file. Generally you have two Webpack configs, one for local development and one for production deployment.
本文标签: javascriptWebpack Bundle FileWhat Does it DoStack Overflow
版权声明:本文标题:javascript - Webpack Bundle File - What Does it Do? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745217887a2648256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论