Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit a5509b8

Browse files
In Angular 2 template, always load CSS via ExtractTextPlugin (otherwise you get a bad FOUC when loading server-prerendered page)
1 parent f830a5f commit a5509b8

File tree

9 files changed

+22
-32
lines changed

9 files changed

+22
-32
lines changed

templates/Angular2Spa/ClientApp/boot-client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'bootstrap/dist/css/bootstrap.css';
2+
import './styles/site.css';
23

34
import { bootstrap } from 'angular2/platform/browser';
45
import { FormBuilder } from 'angular2/common';

templates/Angular2Spa/ClientApp/components/app/app.css

-6
This file was deleted.

templates/Angular2Spa/ClientApp/components/app/app.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Counter } from '../counter/counter';
1616
])
1717
@ng.View({
1818
template: require('./app.html'),
19-
styles: [require('./app.css')],
2019
directives: [NavMenu, router.ROUTER_DIRECTIVES]
2120
})
2221
export class App {

templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import * as router from 'angular2/router';
66
})
77
@ng.View({
88
template: require('./nav-menu.html'),
9-
directives: [router.ROUTER_DIRECTIVES],
10-
styles: [require('./nav-menu.css')]
9+
directives: [router.ROUTER_DIRECTIVES]
1110
})
1211
export class NavMenu {
1312
}

templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.css templates/Angular2Spa/ClientApp/styles/site.css

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
@media (max-width: 767px) {
2+
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
3+
.body-content {
4+
padding-top: 50px;
5+
}
6+
}
7+
18
.main-nav li .glyphicon {
29
margin-right: 10px;
310
}
@@ -10,7 +17,6 @@
1017
color: white;
1118
}
1219

13-
1420
/* Keep the nav menu independent of scrolling and on top of other items */
1521
.main-nav {
1622
position: fixed;

templates/Angular2Spa/Views/Shared/_Layout.cshtml

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - WebApplicationBasic</title>
77
<base href="/" />
8-
9-
<environment names="Staging,Production">
10-
<link rel="stylesheet" href="~/dist/site.css" />
11-
</environment>
8+
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/dist/styles.css" asp-append-version="true" />
1210
</head>
1311
<body>
1412
@RenderBody()
+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
module.exports = {
2-
devtool: 'inline-source-map',
3-
module: {
4-
loaders: [
5-
{ test: /\.css/, exclude: /ClientApp/, loader: 'style!css' }
6-
]
7-
}
2+
devtool: 'inline-source-map'
83
};

templates/Angular2Spa/webpack.config.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
var path = require('path');
22
var webpack = require('webpack');
33
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
4+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
5+
var extractSiteCSS = new ExtractTextPlugin('styles.css');
6+
var extractVendorCSS = new ExtractTextPlugin('vendor.css');
47
var devConfig = require('./webpack.config.dev');
58
var prodConfig = require('./webpack.config.prod');
69
var isDevelopment = process.env.ASPNET_ENV === 'Development';
@@ -13,13 +16,14 @@ module.exports = merge({
1316
loaders: [
1417
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader' },
1518
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
16-
{ test: /\.css$/, include: /ClientApp/, loader: 'raw-loader' },
17-
{ test: /\.html$/, loader: 'raw-loader' }
19+
{ test: /\.html$/, loader: 'raw-loader' },
20+
{ test: /\.css/, include: /bootstrap/, loader: extractVendorCSS.extract(['css']) },
21+
{ test: /\.css/, exclude: /bootstrap/, loader: extractSiteCSS.extract(['css']) },
1822
]
1923
},
2024
entry: {
2125
main: ['./ClientApp/boot-client.ts'],
22-
vendor: ['angular2/bundles/angular2-polyfills.js', 'bootstrap', 'bootstrap/dist/css/bootstrap.css', 'style-loader', 'jquery', 'angular2/core', 'angular2/common', 'angular2/http', 'angular2/router', 'angular2/platform/browser']
26+
vendor: ['angular2/bundles/angular2-polyfills.js', 'bootstrap', 'style-loader', 'jquery', 'angular2/core', 'angular2/common', 'angular2/http', 'angular2/router', 'angular2/platform/browser']
2327
},
2428
output: {
2529
path: path.join(__dirname, 'wwwroot', 'dist'),
@@ -29,6 +33,8 @@ module.exports = merge({
2933
plugins: [
3034
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
3135
new webpack.optimize.OccurenceOrderPlugin(),
32-
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js') // Moves vendor content out of other bundles
36+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'), // Moves vendor content out of other bundles
37+
extractSiteCSS,
38+
extractVendorCSS
3339
]
3440
}, isDevelopment ? devConfig : prodConfig);

templates/Angular2Spa/webpack.config.prod.js

-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
var webpack = require('webpack');
2-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
3-
var extractCSS = new ExtractTextPlugin('site.css');
42

53
module.exports = {
6-
module: {
7-
loaders: [
8-
{ test: /\.css/, exclude: /ClientApp/, loader: extractCSS.extract(['css']) },
9-
]
10-
},
114
plugins: [
12-
extractCSS,
135
new webpack.optimize.UglifyJsPlugin({
146
minimize: true,
157
mangle: false // Due to https://github.com/angular/angular/issues/6678

0 commit comments

Comments
 (0)