asp.net – .Net Core 2 Spa模板与角度材料
| 
                         试图让Angular Material或任何第三方控制集真正地使用这个新模板而苦苦挣扎.在这个新模板中,webpack分为TreeShakable和NonTreeShakable.此外,app.module现在是app.module.shared,app.module.browser,app.module.server. 由于我试图使其工作,应用程序将仅使用app.module.browser中配置的模块运行,但材料标签未得到处理.尝试简单的东西并尝试按钮.我没有收到任何错误,但没有错误.我在Plunker中找到了他们的例子,复制了它生成的内容,它显示正确告诉我,我至少得到了正确的CSS. 包括webpack供应商配置作为起点,因为这似乎是关键因为它如何捆绑css和js. TIA Webpack.vendor
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const treeShakableModules = [
    '@angular/animations','@angular/common','@angular/compiler','@angular/core','@angular/forms','@angular/http','@angular/platform-browser','@angular/platform-browser-dynamic','@angular/router','@angular/material','@angular/cdk','zone.js'
];
const nonTreeShakableModules = [
    'bootstrap','jqwidgets-framework',"@angular/material/prebuilt-themes/indigo-pink.css",'bootstrap/dist/css/bootstrap.css','font-awesome/css/font-awesome.css','es6-promise','es6-shim','event-source-polyfill','jquery',];
const allModules = treeShakableModules.concat(nonTreeShakableModules);
module.exports = (env) => {
    const extractCSS = new ExtractTextPlugin('vendor.css');
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },resolve: { extensions: [ '.js' ] },module: {
            rules: [
                { test: /.(png|woff|woff2|eot|ttf|svg)(?|$)/,use: 'url-loader?limit=100000' }
            ]
        },output: {
            publicPath: 'dist/',filename: '[name].js',library: '[name]_[hash]'
        },plugins: [
            new webpack.ProvidePlugin({ $: 'jquery',jQuery: 'jquery' }),// Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
            new webpack.ContextReplacementPlugin(/@angularb.*b(bundles|linker)/,path.join(__dirname,'./ClientApp')),// Workaround for https://github.com/angular/angular/issues/11580
            new webpack.ContextReplacementPlugin(/angular(|/)core(|/)@angular/,// Workaround for https://github.com/angular/angular/issues/14898
            new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100
        ]
    };
    const clientBundleConfig = merge(sharedConfig,{
        entry: {
            // To keep development builds fast,include all vendor dependencies in the vendor bundle.
            // But for production builds,leave the tree-shakable ones out so the AOT compiler can produce a smaller bundle.
            vendor: isDevBuild ? allModules : nonTreeShakableModules
        },output: { path: path.join(__dirname,'wwwroot','dist') },module: {
            rules: [
                { test: /.css(?|$)/,use: extractCSS.extract({ use: isDevBuild ? 'css-loader' : 'css-loader?minimize' }) }
            ]
        },plugins: [
            extractCSS,new webpack.DllPlugin({
                path: path.join(__dirname,'dist','[name]-manifest.json'),name: '[name]_[hash]'
            })
        ].concat(isDevBuild ? [] : [
            new webpack.optimize.UglifyJsPlugin()
        ])
    });
    const serverBundleConfig = merge(sharedConfig,{
        target: 'node',resolve: { mainFields: ['main'] },entry: { vendor: allModules.concat(['aspnet-prerendering']) },output: {
            path: path.join(__dirname,'ClientApp','dist'),libraryTarget: 'commonjs2',},module: {
            rules: [ { test: /.css(?|$)/,use: ['to-string-loader',isDevBuild ? 'css-loader' : 'css-loader?minimize' ] } ]
        },plugins: [
            new webpack.DllPlugin({
                path: path.join(__dirname,name: '[name]_[hash]'
            })
        ]
    });
    return [clientBundleConfig,serverBundleConfig];
}
解决方法您需要在nonTreeShakableModules中包含角度材质和cdk,如:const treeShakableModules = [
    '@angular/animations','zone.js',];
const nonTreeShakableModules = [
    'bootstrap','@angular/material/prebuilt-themes/indigo-pink.css',]; 
 确保已使用以下2个命令从npm安装了角度材质和cdk模块(动画模块是可选的): npm install --save @angular/material @angular/cdk npm install --save @angular/animations 这应该在package.json中添加以下行: "@angular/animations": "https://registry.npmjs.org/@angular/animations/-/animations-4.2.5.tgz","@angular/cdk": "^2.0.0-beta.8","@angular/material": "^2.0.0-beta.8", 您现在应该尝试使用cmd或PowerShell中的以下命令执行webpack build: webpack --config webpack.config.vendor.js 如果没有错误,您可以在app.module.shared.ts中包含要使用的组件: // angular material modules
import {
    MdAutocompleteModule,MdButtonModule,MdButtonToggleModule,MdCardModule,MdCheckboxModule,MdChipsModule,MdCoreModule,MdDatepickerModule,MdDialogModule,MdExpansionModule,MdGridListModule,MdIconModule,MdInputModule,MdListModule,MdMenuModule,MdNativeDateModule,MdPaginatorModule,MdProgressBarModule,MdProgressSpinnerModule,MdRadioModule,MdRippleModule,MdSelectModule,MdSidenavModule,MdSliderModule,MdSlideToggleModule,MdSnackBarModule,MdSortModule,MdTableModule,MdTabsModule,MdToolbarModule,MdTooltipModule,} from '@angular/material';
import { CdkTableModule } from '@angular/cdk'; 
 并将它们添加到@NgModule中的导入 在下一次修复之前,仍有一些组件被窃听.就像复选框组件在刷新页面时破坏服务器端渲染一样.但它将在下一个版本中修复(它已经在主分支上). (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
- asp.net-mvc – MVC会话过期而不是身份验证
 - asp.net-mvc – 当Bundling EnableOptimizations为true时,F
 - asp.net – WebBrowsable vs个性化Web部件
 - asp.net-mvc-3 – 应该如何看待“分离”?
 - Asp.NEt邮箱验证修改密码通过邮箱找回密码功能
 - asp.net – Razor base type / Templated Razor使用“using
 - asp.net – 应用程序池在iisreset之后无法启动
 - asp.net – MVC 3,(razor)加载部分与验证
 - Asp.net配合easyui实现返回json数据实例
 - asp.net – Ajax Control Toolkit正在加载太多脚本资源
 
- asp.net-core – 具有取消令牌的自定义AspCore中
 - 介绍几种 ADO.net 中的数据库连接方式
 - IIS会话超时与ASP.NET会话超时
 - asp.net-mvc – ASP.NET MVC:添加将DisplayName
 - 在ASP.NET中下载文件的实现代码
 - 从app_data中删除文件夹时如何防止asp.net重新编
 - asp.net-mvc – 从Api控制器内生成绝对的url to
 - asp.net-mvc – 将viewdata传递给asp.net mvc ma
 - asp.net – 如何序列化LINQ-to-SQL惰性列表
 - asp.net-ajax – ASP.Net AJAX UpdatePanel无法触
 
