使用webpack。应用程序编译成功,但在浏览器浮动错误:
"未捕获的TypeError:__ webpack_require __(...)。native不是函数"。
浏览器指示字符串" BSON = require(' bson')。native()。BSON"来自mongodb-core / lib / topologies / server.js(使用mongodb安装)。
我的webpack comman配置文件:
module.exports = {
entry: {
'polyfills': './client/polyfills.ts',
'vendor': './client/vendor.ts',
'client': './client/main.ts'
},
resolve: {
extensions: ['', '.js', '.ts', '.json']
},
module: {
preLoaders: [
{
test: /\.json$/,
loader: 'json-loader'
}
],
loaders: [
{
test: /\.ts$/,
loader: 'ts'
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('client', 'component'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.css$/,
include: helpers.root('client', 'component'),
loader: 'raw'
},
{
test: require.resolve("jquery"),
loader: "imports?jQuery=jquery"
}
]
},
node: {
fs: "empty",
net: 'empty',
tls: 'empty',
module: 'empty'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['client', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'index.html'
// template: 'index.html'
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
};

开发配置:
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
module.exports = webpackMerge(commonConfig, {
// devtool: 'cheap-module-eval-source-map',
devtool: "source-map",
output: {
path: helpers.root('dist'),
publicPath: 'http://localhost:8080/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});

如果需要其他一些想法,我可以提供它。感谢。