我有以下设置Angular2应用程序。如果加载webpack服务器,块可以正常工作并呈现应用程序。最终的包将与.net mvc一起使用,我只是将外部脚本引用标记添加到HTML文件中。一旦我尝试在.NET MVC框架中加载bundle,我就会收到以下错误。
Uncaught ReferenceError: __webpack_require__ is not defined
我尝试过创建一个包含所有依赖项的入口点,但仍然收到错误。我错过了什么或不了解Webpack?
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var helpers = require('./helpers');
var path = require('path');
var context = path.resolve( __dirname, '..');
var distPath = helpers.distPath(path.join(__dirname, '../'));
module.exports = {
context: context,
entry: {
polyfills: './resources/polyfills.js',
vendors: './resources/vendors.js',
main: './main.js'
},
resolve: {
extensions: ['', '.js', '.css', '.scss', '.html']
},
resolveLoader: {
root: path.join(__dirname, '../', "node_modules")
},
output: {
path: distPath,
filename: '[name].js',
chunkFilename: '[id].chunk.js',
sourceMapFilename: '[name].map',
pathInfo: true
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel" },
{ 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('components', 'root'),
loaders: [ExtractTextPlugin.extract('style', 'css?sourceMap'), 'raw']
},
{ test: /\.scss$/, loader:'raw!sass?sourceMap!sass-resources'}
]
},
sassResources: [
'./components/root/main.scss'
],
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['vendors', 'polyfills']
}),
new ExtractTextPlugin("main.min.css")
]
};
将脚本加载到html:
我也试过玩订单但没有运气。