我尝试创建一个简单的表单验证,并通过示例项目中的 yarn 链接注册它以测试设置。但这绝对行不通,我不知道如何继续。
export default class Proofr {
constructor() {
console.log('test');
}
}
这个“脚本”然后由webpack
, with eslint-loader
and babel-loader
(presets env & stage-0) 生成。
因此,它不应该仅仅为了有趣的记录消息而做更多的事情。但是当我尝试调用它时,new Proofr()
它告诉我以下内容:
form.js:25 Uncaught TypeError: _proofr2.default is not a constructor
但如果它不是构造函数,那么它是什么?它是一个空对象,至少 crome 开发工具是这么说的。我导入通过纱线链接链接到我的项目的 js 文件中的校对器。
import Proofr from 'proofr';
import PinguComponent from '../../assets/js/helpers/PinguComponent';
class Form extends PinguComponent {
constructor(el) {
const defaultOpts = {
classes: {
dom: {},
state: {},
},
customEvents: {},
};
const defaultData = {};
super(el, defaultOpts, defaultData);
new Proofr();
this.log('Form loaded');
}
}
export default Form;
因此,据我所知,也许有人看到了最可能非常小的错字。两个存储库都使用相同的 babelrc,因此它们使用相同的预设。
这里是由 webpack 和 babel 生成的用于校对的文件
/******/ (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 = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Proofr a lightweight js tool
*/
var Proofr = function Proofr() {
_classCallCheck(this, Proofr);
console.log('test');
};
exports.default = Proofr;
/***/ })
/******/ ]);
如果您想自己查看,可以通过 npm install proofr(或 yarn proofr)添加