我有這樣的WebPack配置:
const path = require('path');
module.exports = {
entry: ['babel-polyfill', './lib/index.js'],
output: {
path: path.resolve(__dirname + '/dist'),
filename: 'suman.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
options: {
presets: ['latest'],
plugins: ['transform-runtime']
}
}
]
},
node: {
assert: 'empty',
buffer: 'mock',
child_process: 'empty',
cluster: 'empty',
console: 'mock',
constants: 'empty',
crypto: 'empty',
dgram: 'empty',
dns: 'mock',
domain: 'empty',
events: 'empty',
fs: 'empty',
http: 'empty',
https: 'empty',
module: 'empty',
net: 'mock',
os: 'empty',
path: 'empty',
process: 'mock',
punycode: 'mock',
querystring: 'empty',
readline: 'empty',
repl: 'empty',
stream: 'empty',
string_decoder: 'empty',
timers: 'empty',
tls: 'mock',
tty: 'mock',
url: 'empty',
util: 'empty',
v8: 'mock',
vm: 'empty',
zlib: 'empty',
}
};
我運行在命令行$的WebPack和我得到一個輸出文件,我加載文件中的瀏覽器像這樣:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Suman tests</title>
<script src="../../../dist/suman.js"></script>
</head>
<body>
</body>
</html>
如果我在瀏覽器中加載這個HTML文件,我得到:
suman.js:48039 Uncaught TypeError: $export is not a function
at Object.<anonymous> (suman.js:48039)
at __webpack_require__ (suman.js:20)
at Object.<anonymous> (suman.js:46862)
at __webpack_require__ (suman.js:20)
at Object.hasOwnProperty (suman.js:12300)
at __webpack_require__ (suman.js:20)
at Object.<anonymous> (suman.js:10477)
at __webpack_require__ (suman.js:20)
at Object.<anonymous> (suman.js:12321)
at __webpack_require__ (suman.js:20)
我看着在Github上一堆的問題,並沒有任何的他們似乎解決了這個問題。任何人都知道什麼可能是錯的?
我在Webpack版本2.3.3上。
在旁註 - 我在哪裏可以找到一些用於Node.js/NPM模塊的polyfills?
$export
似乎受到的WebPack生成的功能,這裏是它的一些出現在我的輸出文件:
var global = __webpack_require__(10),
core = __webpack_require__(58),
hide = __webpack_require__(33),
redefine = __webpack_require__(34),
ctx = __webpack_require__(59),
PROTOTYPE = 'prototype';
var $export = function $export(type, name, source) {
var IS_FORCED = type & $export.F,
IS_GLOBAL = type & $export.G,
IS_STATIC = type & $export.S,
IS_PROTO = type & $export.P,
IS_BIND = type & $export.B,
target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE],
exports = IS_GLOBAL ? core : core[name] || (core[name] = {}),
expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}),
key,
own,
out,
exp;
if (IS_GLOBAL) source = name;
for (key in source) {
'$ export'是什麼?如果那是失敗的,那就是開始的地方,而且你沒有向我們展示這個代碼。 – loganfsmyth
你還應該考慮用'devtool:「source-map」'啓用sourcemaps,這樣你可以獲得更好的堆棧跟蹤。 – loganfsmyth
@loganfsmyth $ export函數不是我的代碼,它是webpack生成的代碼,讓我給你一個鏈接吧 –