【发布时间】:2018-01-12 02:32:38
【问题描述】:
嗯,我知道 Webpack 允许我们使用 require 导入包,这就是 Webpack 的基础设施。
但是,在入口文件中不使用require不是没用吗?
我有这个test.js 条目:
console.log('Test');
和输出
/******/ (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] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = 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;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(2);
/***/ }),
/* 2 */
/***/ (function(module, exports) {
console.log('Test');
/***/ })
/******/ ]);
这是无用的代码,也阻止了我使用全局变量!
至少对我来说是这样!这就是为什么我想知道是否有任何插件或解决方法可以删除它?
【问题讨论】:
-
仍然想知道 Webpack 是否能够在没有模块加载器引导的情况下输出包,正如 Rollup 可以实现的那样。
-
@Robula 有一个未解决的问题,请查看github.com/webpack/webpack/issues/2638
-
我完全不明白您为什么要使用 WebPack 或希望使用全局变量。您的项目似乎不需要 WebPack 或 Rollup,因此您应该完全删除它们。
-
@sctskw 显然
console.log('Test');不是我的项目 :) 我需要一个 es6 的转译器
标签: javascript node.js webpack