[英]webpack with react.js aspnet - 'global' and 'exports' undefined
我正在嘗試讓一個與aspnet一起工作的react應用程序,並且我正在使用webpack。
這是我的webpack配置
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var pkg = require('./package.json');
// bundle dependencies in separate vendor bundle
var vendorPackages = Object.keys(pkg.dependencies).filter(function (el) {
return el.indexOf('font') === -1; // exclude font packages from vendor bundle
});
/*
* Default webpack configuration for development
*/
var config = {
devtool: 'eval-source-map',
cache: true,
entry: {
main: path.join(__dirname, "app", "App.js"),
vendor: vendorPackages
},
output: {
path: path.join(__dirname, "js"),
filename: '[name].js',
sourceMapFilename: "[file].map"
},
resolve: {
modulesDirectories: ['node_modules'], alias: {}, extensions: ['', '.jsx', '.js']
},
plugins: [
new webpack.OldWatchingPlugin(), //needed to make watch work. see http://stackoverflow.com/a/29292578/1434764
new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.js")
],
resolveLoader: {
'fallback': path.join(__dirname, 'node_modules')
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015','react']
}
}, {
test: /\.css$/,
loader: 'style!css!'
}]
}
}
/*
* If bundling for production, optimize output
*/
if (process.env.NODE_ENV === 'production') {
config.devtool = false;
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
comments: false,
compress: { warnings: false}
}),
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify('production')}
})
];
};
module.exports = config;
嘗試訪問該頁面時,我在控制台中遇到了這兩個錯誤。
SCRIPT5009:'global'是未定義的vendor.js(42739,2)
腳本5009:'出口'是未定義的mobilelobbyapp.js(1,1)
我不知道如何解決這些問題。 我確實在一個工作示例中注意到從webpack導出的js文件具有
webpackJsonp([0],{
在我的文件所在的位置
exports.ids = [0];
exports.modules = {
我在運行webpack后發現此帖子“ global”未定義,並且能夠修復SCRIPT5009:通過添加“ global”是未定義的vendor.js
新的webpack.DefinePlugin({global:{}}),
plugins: [
new webpack.OldWatchingPlugin(), //needed to make watch work. see https://stackoverflow.com/a/29292578/1434764
new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.js"),
new webpack.DefinePlugin({ global: {} }),
],
然后我修復了SCRIPT5009:通過刪除未定義'exports'
target: 'node',
從我的webpack.config
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.