asp.net – 找不到’AppModule’的NgModule元数据使用–env.prod
我正在尝试将ASP.NET Core Angular 4 SPA项目从.NET Core 2.0.0 / Angular4升级到.NET Core 2.0.3 / Angular5.除了在生产环境中进行服务器端渲染之外,我设法让一切正常工作,当我发布应用程序时i / e:
只有在满足以上两个条件时才会出现此问题: > Webpack使用–env.prod开关构建软件包 < app asp-prerender-module =“ClientApp / dist / main-server”>正在加载…< / app> 如果我删除开关和/或参数,问题就会消失(与SSR一起). 我可以提供一些其他信息: >它不是与IIS相关的东西,它发生在Kestrel级别. 可悲的是,我无法恢复到原来的AotPlugin,因为它也会抛出错误 – 这是完全可以理解的,因为它并不意味着与Angular5一起使用. 软件版本 > .NET Core 2.0.3 webpack.config.js const path = require('path'); const webpack = require('webpack'); const merge = require('webpack-merge'); const AotPlugin = require('@ngtools/webpack').AngularCompilerPlugin; const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; module.exports = (env) => { // Configuration in common to both client-side and server-side bundles const isDevBuild = !(env && env.prod); const sharedConfig = { stats: { modules: false },context: __dirname,resolve: { extensions: [ '.js','.ts' ] },output: { filename: '[name].js',publicPath: 'dist/' // Webpack dev middleware,if enabled,handles requests for this URL prefix },module: { rules: [ { test: /(?:.ngfactory.js|.ngstyle.js|.ts)$/,include: /ClientApp/,use: isDevBuild ? ['awesome-typescript-loader?silent=true','angular2-template-loader'] : '@ngtools/webpack' },{ test: /.html$/,use: 'html-loader?minimize=false' },{ test: /.css$/,use: [ 'to-string-loader',isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },{ test: /.(png|jpg|jpeg|gif|svg)$/,use: 'url-loader?limit=25000' } ] },plugins: [new CheckerPlugin()] }; // Configuration for client-side bundle suitable for running in browsers const clientBundleOutputDir = './wwwroot/dist'; const clientBundleConfig = merge(sharedConfig,{ entry: { 'main-client': './ClientApp/boot.browser.ts' },output: { path: path.join(__dirname,clientBundleOutputDir) },plugins: [ new webpack.DllReferencePlugin({ context: __dirname,manifest: require('./wwwroot/dist/vendor-manifest.json') }) ].concat(isDevBuild ? [ // Plugins that apply in development builds only new webpack.SourceMapDevToolPlugin({ filename: '[file].map',// Remove this line if you prefer inline source maps moduleFilenameTemplate: path.relative(clientBundleOutputDir,'[resourcePath]') // Point sourcemap entries to the original file locations on disk }) ] : [ // Plugins that apply in production builds only new webpack.optimize.UglifyJsPlugin(),new AotPlugin({ tsConfigPath: './tsconfig.json',entryModule: path.join(__dirname,'ClientApp/app/app.module.browser#AppModule'),exclude: ['./**/*.server.ts'] }) ]) }); // Configuration for server-side (prerendering) bundle suitable for running in Node const serverBundleConfig = merge(sharedConfig,{ resolve: { mainFields: ['main'] },entry: { 'main-server': './ClientApp/boot.server.ts' },manifest: require('./ClientApp/dist/vendor-manifest.json'),sourceType: 'commonjs2',name: './vendor' }) ].concat(isDevBuild ? [] : [ // Plugins that apply in production builds only new AotPlugin({ tsConfigPath: './tsconfig.json','ClientApp/app/app.module.server#AppModule'),exclude: ['./**/*.browser.ts'] }) ]),output: { libraryTarget: 'commonjs',path: path.join(__dirname,'./ClientApp/dist') },target: 'node',devtool: 'inline-source-map' }); return [clientBundleConfig,serverBundleConfig]; }; 解决方法
Angular 5的
@ngtool/webpack configuration与Angular 2/4有些不同.所以,我已经改变了webpack.config.js如下,
const path = require('path'); const webpack = require('webpack'); const merge = require('webpack-merge'); const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin; const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; module.exports = (env) => { // Configuration in common to both client-side and server-side bundles const isDevBuild = !(env && env.prod); const sharedConfig = { stats: { modules: false },module: { rules: [ { test: /.ts$/,use: 'url-loader?limit=25000' },{ test: /(?:.ngfactory.js|.ngstyle.js)$/,loader: '@ngtools/webpack',options: { tsConfigPath: '/tsconfig.json',} } ] },'[resourcePath]') // Point sourcemap entries to the original file locations on disk }) ] : [ // Plugins that apply in production builds only new webpack.optimize.UglifyJsPlugin(),new AngularCompilerPlugin({ tsConfigPath: './tsconfig.json',exclude: ['./**/*.server.ts'] }) ]) }); // Configuration for server-side (prerendering) bundle suitable for running in Node const serverBundleConfig = merge(sharedConfig,name: './vendor' }) ].concat(isDevBuild ? [] : [ // Plugins that apply in production builds only new AngularCompilerPlugin({ tsConfigPath: './tsconfig.json',serverBundleConfig]; }; 这是我的package.json文件, { "dependencies": { "@angular/animations": "^5.0.2","@angular/cdk": "^5.0.0-rc0","@angular/cli": "^1.6.0-beta.2","@angular/common": "^5.0.2","@angular/compiler": "^5.0.2","@angular/compiler-cli": "^5.0.2","@angular/core": "^5.0.2","@angular/forms": "^5.0.2","@angular/http": "^5.0.2","@angular/material": "^5.0.0-rc0","@angular/platform-browser": "^5.0.2","@angular/platform-browser-dynamic": "^5.0.2","@angular/platform-server": "^5.0.2","@angular/router": "^5.0.2","@ngtools/webpack": "^1.8.3","@types/webpack-env": "^1.13.2","angular2-template-loader": "0.6.2","aspnet-prerendering": "^3.0.1","aspnet-webpack": "^2.0.1","awesome-typescript-loader": "^3.4.0","bootstrap": "3.3.7","css": "2.2.1","css-loader": "^0.28.7","es6-shim": "0.35.3","event-source-polyfill": "0.0.12","expose-loader": "0.7.4","extract-text-webpack-plugin": "^3.0.2","file-loader": "^1.1.5","html-loader": "^0.5.1","isomorphic-fetch": "2.2.1","jquery": "3.2.1","json-loader": "^0.5.7","preboot": "^5.1.7","raw-loader": "0.5.1","reflect-metadata": "0.1.10","request": "^2.83.0","rxjs": "^5.5.2","style-loader": "^0.19.0","to-string-loader": "1.1.5","typescript": "^2.6.1","url-loader": "^0.6.2","webpack": "^3.8.1","webpack-hot-middleware": "^2.20.0","webpack-merge": "^4.1.1","zone.js": "^0.8.18" },"devDependencies": { "@types/chai": "^4.0.5","@types/jasmine": "^2.8.2","@types/node": "^8.0.53","chai": "^4.1.2","jasmine-core": "2.8.0","karma": "1.7.1","karma-chai": "0.1.0","karma-chrome-launcher": "2.2.0","karma-cli": "1.0.1","karma-jasmine": "1.1.0","karma-webpack": "2.0.6" },"name": "aspnetcoreangularspa","private": true,"scripts": { "test": "karma start ClientApp/test/karma.conf.js" },"version": "0.0.0" } 如果您仍然无法运行该解决方案,请查看此repository以获得有效的解决方案. 希望能帮助到你 :) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET Core的Kestrel服务器
- asp.net-mvc – 使用Action Filter检查URL中的参数的MVC.停
- asp.net-web-api2 – 什么导致swagger已经出现在Web API 2的
- asp.net-mvc – Asp.net MVC中的TimeSpan和“24:00”解析错
- [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Lin
- SCRIPT87:IE 9中无效的参数,ASP.NET C#
- asp.net-mvc – ASP.NET MVC脚手架很慢
- asp.net-mvc – 自定义ActionLink帮助器,它知道你正在使用哪
- asp.net-mvc – ActionLink MVC中的图像按钮
- asp.net-mvc – 在ASP.NET MVC应用程序中测试AutoMapper配置
- asp.net-mvc – ASP.NET MVC 5 Html.HiddenFor呈
- asp.net – 如何关闭.NET站点进行维护?
- msbuild – 如何为ASP.NET 5项目设置TeamCity构建
- asp.net – 如何在url搜索词中处理web.config
- asp.net-mvc – asp.net mvc5 webapi2,如何通过r
- asp.net-mvc – 如何为MVC创建具有1对多关联的虚
- asp.net-mvc – 定义脚手架. (关于动态数据和ASP
- ASP.NET – 如何检查浏览器支持html5?
- asp.net-mvc – 使用OWIN的Google身份验证Oauth在
- asp.net mvc.显示数据库中的html字符串