babel-loader没起作用,还是ES6的语法

babel-loader没起作用,还是ES6的语法

目录:

https://img1.sycdn.imooc.com//climg/64c8db8909eeecbb02050264.jpg

https://img1.sycdn.imooc.com//climg/64c8db9809b25caf06430461.jpg

https://img1.sycdn.imooc.com//climg/64c8dba40987aeaf03610179.jpg

https://img1.sycdn.imooc.com//climg/64c8dbc009c3ac9a05130423.jpg

得出来的代码

相关截图:

/******/ (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, { enumerable: true, get: getter });
/******/    }
/******/  };
/******/
/******/  // define __esModule on exports
/******/  __webpack_require__.r = function(exports) {
/******/    if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/      Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/    }
/******/    Object.defineProperty(exports, '__esModule', { value: true });
/******/  };
/******/
/******/  // create a fake namespace object
/******/  // mode & 1: value is a module id, require it
/******/  // mode & 2: merge all properties of value into the ns
/******/  // mode & 4: return value when already ns object
/******/  // mode & 8|1: behave like require
/******/  __webpack_require__.t = function(value, mode) {
/******/    if(mode & 1) value = __webpack_require__(value);
/******/    if(mode & 8) return value;
/******/    if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/    var ns = Object.create(null);
/******/    __webpack_require__.r(ns);
/******/    Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/    if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/    return ns;
/******/  };
/******/
/******/  // 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 = "./src/index.js");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./src/index.js":
/*!**********************!*\
  !*** ./src/index.js ***!
  \**********************/
/*! no static exports found */
/***/ (function(module, exports) {

eval("const liList = document.querySelectorAll('li');\nfor (let i=0;i<liList.length;i++){\n    let content = liList[i].innerText;\n    liList[i].onmouseover = function () {\n        liList[i].innerText = content+'我是第' + (i+1) + '个';\n        liList[i].style.fontSize = '20px'\n        liList[i].style.color = 'red';\n    }\n    liList[i].onmouseleave = function () {\n        liList[i].style.color = 'black';\n        liList[i].style.fontSize = '16px';\n        liList[i].innerText = content;\n    }\n}\n\nclass Person{\n\n}\n\nfunction P(name, age){\n    this.name = name;\n    this.age = age;\n}\n\nnew Promise(() => {\n\n})\n\n//# sourceURL=webpack:///./src/index.js?");

/***/ })

/******/ });

nodejs是最新的LTS版本(18.17.0)

下面是只用babel编译过的

"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var liList = document.querySelectorAll('li');
var _loop = function _loop(i) {
var content = liList[i].innerText;
liList[i].onmouseover = function () {
liList[i].innerText = content + '我是第' + (i + 1) + '个';
liList[i].style.fontSize = '20px';
liList[i].style.color = 'red';
};
liList[i].onmouseleave = function () {
liList[i].style.color = 'black';
liList[i].style.fontSize = '16px';
liList[i].innerText = content;
};
};
for (var i = 0; i < liList.length; i++) {
_loop(i);
}
var Person = /*#__PURE__*/_createClass(function Person() {
_classCallCheck(this, Person);
});
function P(name, age) {
this.name = name;
this.age = age;
}
new Promise(function () {});


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小李 2023-08-01 18:24:41

同学你好,把node版本降下来建议v12试一试。祝学习愉快!

  • 提问者 阿大月 #1

    我现在换成了12.22.12的,还是不行,没有变化

    2023-08-02 15:55:02
  • 好帮手慕小李 回复 提问者 阿大月 #2

    同学提供的版本老师这边测试结果是没有问题的。

    https://img1.sycdn.imooc.com//climg/64ca15f3099ca0c410760380.jpg

    https://img1.sycdn.imooc.com//climg/64ca160909ed5b7518310493.jpg

    老师猜测可能是因为同学当前电脑中带有其他环境导致的问题。如有条件的话同学尝试使用非测试环境再试试。

    2023-08-02 16:03:21
  • 提问者 阿大月 回复 好帮手慕小李 #3

    我把课件源码下载下来试了一下是可以的,在我自己的电脑上测试我自己的不行,还是原来的样子,应该是我配置的原因,具体是哪我还没找到

    2023-08-06 15:46:13
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师