这是 webpack.config.js
"use strict";
var webpack = require('webpack')
module.exports = {
entry: ['./main.js'],
output: { path: __dirname, filename: 'bundle.js' },
module: {
loaders: [
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
},
{test: /\.json$/, loader: "json"},
]
},
externals: {
React: 'react',
},
target: "node",
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
'global': {},
})
],
};
Main.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Table, Column, Cell} from 'fixed-data-table';
import Chart from 'chartjs';
import jQuery from 'jquery';
import vis from 'vis';
import babel from 'babel-core';
Bundle.js 已插入我的Index.html。浏览器然后给出错误:
Uncaught TypeError: (intermediate value).setTimeout is not a function
at requestAnimationFrame (bundle.js:21935)
at Object.<anonymous> (bundle.js:21941)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:21187)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:20136)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:19602)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:19553)
导致此错误的原因是什么,以及如何更改webpack配置以使其消失?
答案 0 :(得分:2)
我通过将webpack配置中的global定义为插件,并使用空输入解决了这个问题。
'global': {},
答案 1 :(得分:0)
在Gulp中Babelify之后使用uglify()
解决。
示例:
.transform(babelify.configure({presets: ['@babel/preset-env']}))
.bundle() .pipe(source('app.js')) .pipe(buffer()) .pipe(uglify())