代码之家  ›  专栏  ›  技术社区  ›  Mike_G

将角度材质添加到Asp。Net Core 2水疗中心

  •  1
  • Mike_G  · 技术社区  · 7 年前

    我好像没法把这件事办好。我在SO和网络上找到的零碎信息已经过时,似乎不完整。

    这是我的包裹。json:

    {
      "name": "MyProj.Site",
      "private": true,
      "version": "0.0.0",
      "scripts": {
        "test": "karma start ClientApp/test/karma.conf.js"
      },
      "devDependencies": {
        "@angular/animations": "5.1.1",
        "@angular/common": "5.1.1",
        "@angular/compiler": "5.1.1",
        "@angular/compiler-cli": "5.1.1",
        "@angular/core": "5.1.1",
        "@angular/forms": "5.1.1",
        "@angular/http": "5.1.1",
        "@angular/platform-browser": "5.1.1",
        "@angular/platform-browser-dynamic": "5.1.1",
        "@angular/platform-server": "5.1.1",
        "@angular/router": "5.1.1",
        "@ngtools/webpack": "1.9.1",
        "@types/chai": "4.0.1",
        "@types/jasmine": "2.5.53",
        "@types/webpack-env": "1.13.3",
        "angular2-router-loader": "0.3.5",
        "angular2-template-loader": "0.6.2",
        "aspnet-prerendering": "^3.0.1",
        "aspnet-webpack": "^2.0.1",
        "@angular/material": "5.0.1",
        "@angular/cdk": "5.0.1",
        "awesome-typescript-loader": "3.4.1",
        "bootstrap": "4.0.0-beta.2",
        "chai": "4.0.2",
        "css": "2.2.1",
        "css-loader": "0.28.4",
        "es6-shim": "0.35.3",
        "event-source-polyfill": "0.0.9",
        "expose-loader": "0.7.3",
        "extract-text-webpack-plugin": "2.1.2",
        "file-loader": "0.11.2",
        "html-loader": "0.4.5",
        "isomorphic-fetch": "2.2.1",
        "jasmine-core": "2.6.4",
        "jquery": "3.2.1",
        "json-loader": "0.5.4",
        "karma": "1.7.0",
        "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.3",
        "preboot": "5.1.7",
        "raw-loader": "0.5.1",
        "reflect-metadata": "0.1.10",
        "rxjs": "5.4.2",
        "style-loader": "0.18.2",
        "to-string-loader": "1.1.5",
        "typescript": "2.6.1",
        "url-loader": "0.5.9",
        "webpack": "3.10.0",
        "webpack-hot-middleware": "2.21.0",
        "webpack-merge": "4.1.1",
        "zone.js": "0.8.12",
        "hammerjs": "2.0.8"
      }
    }
    

    我的网页包。配置。小贩js公司:

    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',
        'zone.js',
        '@angular/cdk'
    ];
    const nonTreeShakableModules = [
        'hammerjs/hammer',
        'bootstrap',
        'bootstrap/dist/css/bootstrap.css',
        'es6-promise',
        'es6-shim',
        'event-source-polyfill',
        'jquery',
        '@angular/material/prebuilt-themes/indigo-pink.css',
    
    
    ];
    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(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580
                new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, path.join(__dirname, './ClientApp')), // 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, 'wwwroot', '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, 'ClientApp', 'dist', '[name]-manifest.json'),
                    name: '[name]_[hash]'
                })
            ]
        });
    
        return [clientBundleConfig, serverBundleConfig];
    }
    

    和我的应用程序。共享。单元ts:

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
    import { RouterModule } from '@angular/router';
    
    import { AppComponent } from './components/app/app.component';
    import { NavMenuComponent } from './components/navmenu/navmenu.component';
    import { HomeComponent } from './components/home/home.component';
    import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
    import { CounterComponent } from './components/counter/counter.component';
    
    import { MatButtonModule } from '@angular/material/button';
    
    
    @NgModule({
        declarations: [
            AppComponent,
            NavMenuComponent,
            CounterComponent,
            FetchDataComponent,
            HomeComponent
        ],
        imports: [
            CommonModule,
            HttpModule,
            FormsModule,
            RouterModule.forRoot([
                { path: '', redirectTo: 'home', pathMatch: 'full' },
                { path: 'home', component: HomeComponent },
                { path: 'counter', component: CounterComponent },
                { path: 'fetch-data', component: FetchDataComponent },
                { path: '**', redirectTo: 'home' }
            ]),
            MatButtonModule
        ]
    })
    export class AppModuleShared {
    }
    

    我的供应商。配置编译良好。在VS2017中调试项目时,出现以下错误:

    NodeInvocationException:预渲染失败,原因是错误:错误: 在WebPackageMissingModule中找不到模块“rxjs/operators/take” (C:\Users\Mike\Source\MyProj\ClientApp\dist\main server.js:15733:140)

    如果您能帮助我参考rxjs模块,我将不胜感激。

    2 回复  |  直到 7 年前
        1
  •  4
  •   Kirk Larkin    7 年前

    如图所示 package.json , @angular/material 具有以下依赖关系:

    "rxjs": "^5.5.5"
    

    你有 "rxjs": "5.4.2" 在您的 package.json ,这显然有点落后于此。我发现了一个Github issue 对于flex layout angular软件包,建议升级 rxjs 5.5 解决了该包中的相同问题。我刚刚在您的设置中尝试了这一点,并且可以确认它可以使用上面的5.5.5工作。

    编辑:一旦安装了更新的版本,就需要以正确的顺序重新生成网页包。通过对项目进行解决方案级别的重建,您可能能够实现这一点,但如果无法实现,则可以运行以下操作来强制Web包正确生成:

    webpack --config webpack.config.vendor.js
    webpack
    

    你可能没有 webpack 全局安装-如果不是,则可以使用以下选项(假定为Windows):

    .\node_modules\.bin\webpack --config webpack.config.vendor.js
    .\node_modules\.bin\webpack
    
        2
  •  0
  •   Rahul Uttarkar    7 年前

    在中添加最新版本的角度材质 ASP。net Core 2.0 使用默认安装的节点包,解决包依赖关系更加困难和耗时。

    在包装中使用以下版本的角材料。json

    "@angular/cdk": "^2.0.0-beta.12"

    "@angular/material": "^2.0.0-beta.12"

    然后运行下面的命令来安装它。

    npm install --save