Skip to content

Server side rendering is not working #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jwdelgado opened this issue Jan 17, 2018 · 4 comments · Fixed by #538
Closed

Server side rendering is not working #535

jwdelgado opened this issue Jan 17, 2018 · 4 comments · Fixed by #538

Comments

@jwdelgado
Copy link

I ran the Angular 5.0 Universal & ASP.NET Core advanced starter-kit example, but it only runs the browser version. The Server version that is supposed to be having the server side rendering is not working for me.

Could you please specify how to turn it on as it is not yet turned on.

Also, the working example : http://aspnetcore-angular2-universal.azurewebsites.net/home
has the SSR. If I check on the view source, I could see the rendered html tags in the app-root. The example for Angular 5 does not seem to work.

@10derloin
Copy link

I'm also keen to use SSR with ng5, but it looks like it's still a work in progress.

From the Angular 5 branch readme: "NOTE Currently issues with SSR and 5.x - SSR temporarily removed"

https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/angular-5.0-WIP/README.md

@mcgri
Copy link

mcgri commented Jan 17, 2018

The milestone ticket for this #516 . Just to monitor the progress. As I understand, the main fix for this was done by angular-cli team, so hopefully, it won't be long until the ng5 version would release.

MarkPieszak added a commit that referenced this issue Jan 23, 2018
This works both in Development & Production. 🎁
(Apologies on the delay)

Now dotnet publish won't fail, and you can successfully build Production builds.

In the future, boot.server.PRODUCTION.ts probably won't be needed.

We'll be working on upgrading this to use the CLI version that Steve Sanderson has been working on the past few months - this will clean-up a lot of the configuration so that it's all handled by the CLI itself. (Aka: no more webpack files for us to deal with here) ✨

This should close out many issues:

#535
#482
(others as well, can't find them at the moment)
@MarkPieszak
Copy link
Member

5.0 template now merged into Master via #538
Angular-CLI template will be the next great upgrade to improve everything. #539 to track that

@MMilan19
Copy link

MMilan19 commented Jul 9, 2018

@MarkPieszak , I have built application using Asp.Net core 2.0 with Angular Template in VS2017 with AspNetCoreSPA. After publish site, Everything is working fine except Server side rendering when I access website with domain name or Server IP address. Although, when I accessing using local host on server, server side is working. I am not able to figure out why it is behaving like this. please help me to get rid of it.

This is my package.json file

{
"name": "AspNetCoreSpa",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"@angular/animations": "4.2.5",
"@angular/common": "4.2.5",
"@angular/compiler": "4.2.5",
"@angular/compiler-cli": "4.2.5",
"@angular/core": "4.2.5",
"@angular/forms": "4.2.5",
"@angular/http": "4.2.5",
"@angular/platform-browser": "4.2.5",
"@angular/platform-browser-dynamic": "4.2.5",
"@angular/platform-server": "4.2.5",
"@angular/router": "4.2.5",
"@ngtools/webpack": "1.5.0",
"@types/chai": "4.0.1",
"@types/jasmine": "2.5.53",
"@types/webpack-env": "1.13.0",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"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": "4.5.2",
"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.4.1",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-cli": "^3.0.3",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "0.8.12"
},
"dependencies": {
"@types/jquery": "^3.3.2",
"ng2-bs-dropdown": "^0.7.0",
"ngx-pagination": "^3.1.1"
}
}

here, it's Webpack.config.js file

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
//const AotPlugin = require('@ngtools/webpack').AotPlugin;
const AotPlugin = require('@ngtools/webpack').AotPlugin;
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: /.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-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.browser.module#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' },
    plugins: [
        new webpack.DllReferencePlugin({
            context: __dirname,
            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',
            entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
            exclude: ['./**/*.browser.ts']
        })
    ]),
    output: {
        libraryTarget: 'commonjs',
        path: path.join(__dirname, './ClientApp/dist')
    },
    target: 'node',
    devtool: 'inline-source-map'
});

return [clientBundleConfig, serverBundleConfig];

};

capture


Waiting for your prompt replay,
Thanks,
Milan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants