相关疑难解决方法(0)

如何使用babel和webpack将导出的函数公开到全局范围

如何使用webpack和babel编译我的代码,以便导出的函数在全局范围内可用.

例如:

export function test(){console.log('test')}
Run Code Online (Sandbox Code Playgroud)

应该在window.test().

当我跑步时,babel -d我得到了我所期望的:

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.test = test;

function test() {
  console.log('test');
}
Run Code Online (Sandbox Code Playgroud)

但webpack输出如下所示:

!function(e) {
  function t(r) {
    if (o[r])return o[r].exports;
    var n = o[r] = {exports: {}, id: r, loaded: !1};
    return e[r].call(n.exports, n, n.exports, t), n.loaded = !0, n.exports
  }

  var o = {};
  return t.m = e, t.c = o, t.p = "", t(0)
}([function(e, t) {
  "use strict";
  function o() …
Run Code Online (Sandbox Code Playgroud)

webpack babeljs

11
推荐指数
2
解决办法
9215
查看次数

标签 统计

babeljs ×1

webpack ×1