简单的脚本,我试图缩小
script.js
module.exports = function() {
console.log('webpack script');
};cl args
$ webpack script.js script.min.js --optimize-minimize
$ webpack script.js script.bundled.jsscript.min.js
在浏览器中执行时,它返回false。
var script = !function(o){function r(e){if(t[e])return t[e].exports;var n=t[e]={exports:{},id:e,loaded:!1};return o[e].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=o,r.c=t,r.p="",r(0)}([function(o,r){o.exports=function(){console.log("webpack script")}}]);
script; // => falsescript.bundled.js
/******/ (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) {
module.exports = function() {
console.log('webpack script');
}
/***/ }
/******/ ]);现在我可以在浏览器中完成这个任务了
var script = /* non-minified bundle */
typeof script; // => function效果很好。不知道为什么--optimize-minimize不能工作。
发布于 2016-04-09 09:18:39
Webpack产生了一个生命,这意味着它是自动执行的,在这种情况下,返回值并不重要。所以你不需要运行它。
另一方面,由于script.js是您的入口点,它不应该包含module.exports语句,它应该只执行您想要执行的代码,在本例中:
console.log('webpack script');https://stackoverflow.com/questions/36361389
复制相似问题