Skip to content

Commit 19684f2

Browse files
In Angular2Spa template, use per-component scoped styles. Fixes common config issues like aspnet#234.
1 parent cd18489 commit 19684f2

File tree

8 files changed

+25
-31
lines changed

8 files changed

+25
-31
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import{Component } from '@angular/core'
22

33
@Component({
44
selector: 'app',
5-
template: require('./app.component.html')
5+
template: require('./app.component.html'),
6+
styles: [require('./app.component.css')]
67
})
78
exportclassAppComponent{
89
}

templates/Angular2Spa/ClientApp/styles/site.css renamed to templates/Angular2Spa/ClientApp/app/components/navmenu/navmenu.component.css

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
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-
8-
.main-navli .glyphicon{
1+
li .glyphicon{
92
margin-right:10px;
103
}
114

125
/* Highlighting rules for nav menu items */
13-
.main-navli.link-activea,
14-
.main-navli.link-activea:hover,
15-
.main-navli.link-activea:focus{
6+
li.link-activea,
7+
li.link-activea:hover,
8+
li.link-activea:focus{
169
background-color:#4189C7;
1710
color: white;
1811
}
@@ -32,31 +25,31 @@
3225
height:100%;
3326
width:calc(25%-20px);
3427
}
35-
.main-nav .navbar{
28+
.navbar{
3629
border-radius:0px;
3730
border-width:0px;
3831
height:100%;
3932
}
40-
.main-nav .navbar-header{
33+
.navbar-header{
4134
float: none;
4235
}
43-
.main-nav .navbar-collapse{
36+
.navbar-collapse{
4437
border-top:1px solid #444;
4538
padding:0px;
4639
}
47-
.main-nav .navbarul{
40+
.navbarul{
4841
float: none;
4942
}
50-
.main-nav .navbarli{
43+
.navbarli{
5144
float: none;
5245
font-size:15px;
5346
margin:6px;
5447
}
55-
.main-nav .navbarlia{
48+
.navbarlia{
5649
padding:10px16px;
5750
border-radius:4px;
5851
}
59-
.main-nav .navbara{
52+
.navbara{
6053
/* If a menu item's text is too long, truncate it */
6154
width:100%;
6255
white-space: nowrap;

‎templates/Angular2Spa/ClientApp/app/components/navmenu/navmenu.component.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<divclass='main-nav'>
2-
<divclass='navbar navbar-inverse'>
2+
<divclass='navbar navbar-inverse'>
33
<divclass='navbar-header'>
44
<buttontype='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>
55
<spanclass='sr-only'>Toggle navigation</span>

‎templates/Angular2Spa/ClientApp/app/components/navmenu/navmenu.component.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import{Component } from '@angular/core'
22

33
@Component({
44
selector: 'nav-menu',
5-
template: require('./navmenu.component.html')
5+
template: require('./navmenu.component.html'),
6+
styles: [require('./navmenu.component.css')]
67
})
78
exportclassNavMenuComponent{
89
}

‎templates/Angular2Spa/ClientApp/boot-client.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import 'angular2-universal-polyfills/browser'
22
import{enableProdMode}from'@angular/core';
33
import{platformUniversalDynamic}from'angular2-universal';
44
import{AppModule}from'./app/app.module';
5-
6-
// Include styles in the bundle
75
import'bootstrap';
8-
import'./styles/site.css';
96

107
// Enable either Hot Module Reloading or production mode
118
consthotModuleReplacement=module['hot'];

‎templates/Angular2Spa/Views/Shared/_Layout.cshtml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<title>@ViewData["Title"] - WebApplicationBasic</title>
77
<basehref="/" />
88
<linkrel="stylesheet"href="~/dist/vendor.css"asp-append-version="true" />
9-
<linkrel="stylesheet"href="~/dist/styles.css"asp-append-version="true" />
109
</head>
1110
<body>
1211
@RenderBody()

‎templates/Angular2Spa/webpack.config.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
varpath=require('path');
22
varwebpack=require('webpack');
3-
varExtractTextPlugin=require('extract-text-webpack-plugin');
43

54
varisDevBuild=process.env.ASPNETCORE_ENVIRONMENT==='Development';
6-
varextractCSS=newExtractTextPlugin('styles.css');
75

86
module.exports={
97
devtool: isDevBuild ? 'inline-source-map' : null,
108
resolve: {extensions: ['','.js','.ts']},
119
entry: {main: ['./ClientApp/boot-client.ts']},
1210
module: {
1311
loaders: [
14-
{test: /\.ts$/,include: /ClientApp/,loader: 'ts-loader?silent=true'},
15-
{test: /\.html$/,loader: 'raw-loader'},
16-
{test: /\.css/,loader: extractCSS.extract(['css'])}
12+
{test: /\.ts$/,include: /ClientApp/,loader: 'ts',query: {silent: true}},
13+
{test: /\.html$/,include: /ClientApp/,loader: 'raw'},
14+
{test: /\.css/,include: /ClientApp/,loader: 'raw'}
1715
]
1816
},
1917
output: {
@@ -22,7 +20,6 @@ module.exports ={
2220
publicPath: '/dist/'
2321
},
2422
plugins: [
25-
extractCSS,
2623
newwebpack.DllReferencePlugin({
2724
context: __dirname,
2825
manifest: require('./wwwroot/dist/vendor-manifest.json')

0 commit comments

Comments
(0)