2017-01-04 43 views
2

我想獲得反應的應用程序與aspnet工作,我使用webpack。webpack與react.js aspnet - '全球'和'出口'undefined

這是我的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; 

我收到的控制檯這2個錯誤,當我嘗試訪問的頁面。

SCRIPT5009: '全球性' 未定義 vendor.js(42739,2)

SCRIPT5009: '出口' 是未定義 mobilelobbyapp.js(1,1)

我可以不知道如何解決這些問題。我也注意到在工作的例子,從的WebPack導出的js文件有

webpackJsonp([0],{ 

在哪裏該礦擁有

exports.ids = [0]; 
exports.modules = { 

回答

0

我發現這個職位'global' undefined after running webpack和我能夠fixSCRIPT5009文件的開頭: '全球性' 是未定義vendor.js通過添加

新webpack.DefinePlugin({全球:{}}),以

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: '出口' 是從我webpack.config去除

target: 'node', 

不確定