mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
In Angular 2 template, always load CSS via ExtractTextPlugin (otherwise you get a bad FOUC when loading server-prerendered page)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'bootstrap/dist/css/bootstrap.css';
|
import 'bootstrap/dist/css/bootstrap.css';
|
||||||
|
import './styles/site.css';
|
||||||
|
|
||||||
import { bootstrap } from 'angular2/platform/browser';
|
import { bootstrap } from 'angular2/platform/browser';
|
||||||
import { FormBuilder } from 'angular2/common';
|
import { FormBuilder } from 'angular2/common';
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
@media (max-width: 767px) {
|
|
||||||
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
|
|
||||||
.body-content {
|
|
||||||
padding-top: 50px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,6 @@ import { Counter } from '../counter/counter';
|
|||||||
])
|
])
|
||||||
@ng.View({
|
@ng.View({
|
||||||
template: require('./app.html'),
|
template: require('./app.html'),
|
||||||
styles: [require('./app.css')],
|
|
||||||
directives: [NavMenu, router.ROUTER_DIRECTIVES]
|
directives: [NavMenu, router.ROUTER_DIRECTIVES]
|
||||||
})
|
})
|
||||||
export class App {
|
export class App {
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import * as router from 'angular2/router';
|
|||||||
})
|
})
|
||||||
@ng.View({
|
@ng.View({
|
||||||
template: require('./nav-menu.html'),
|
template: require('./nav-menu.html'),
|
||||||
directives: [router.ROUTER_DIRECTIVES],
|
directives: [router.ROUTER_DIRECTIVES]
|
||||||
styles: [require('./nav-menu.css')]
|
|
||||||
})
|
})
|
||||||
export class NavMenu {
|
export class NavMenu {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
@media (max-width: 767px) {
|
||||||
|
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
|
||||||
|
.body-content {
|
||||||
|
padding-top: 50px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.main-nav li .glyphicon {
|
.main-nav li .glyphicon {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
@@ -10,7 +17,6 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Keep the nav menu independent of scrolling and on top of other items */
|
/* Keep the nav menu independent of scrolling and on top of other items */
|
||||||
.main-nav {
|
.main-nav {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -5,10 +5,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>@ViewData["Title"] - WebApplicationBasic</title>
|
<title>@ViewData["Title"] - WebApplicationBasic</title>
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
|
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
|
||||||
<environment names="Staging,Production">
|
<link rel="stylesheet" href="~/dist/styles.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="~/dist/site.css" />
|
|
||||||
</environment>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
devtool: 'inline-source-map',
|
devtool: 'inline-source-map'
|
||||||
module: {
|
|
||||||
loaders: [
|
|
||||||
{ test: /\.css/, exclude: /ClientApp/, loader: 'style!css' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var webpack = require('webpack');
|
var webpack = require('webpack');
|
||||||
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
|
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
|
||||||
|
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
var extractSiteCSS = new ExtractTextPlugin('styles.css');
|
||||||
|
var extractVendorCSS = new ExtractTextPlugin('vendor.css');
|
||||||
var devConfig = require('./webpack.config.dev');
|
var devConfig = require('./webpack.config.dev');
|
||||||
var prodConfig = require('./webpack.config.prod');
|
var prodConfig = require('./webpack.config.prod');
|
||||||
var isDevelopment = process.env.ASPNET_ENV === 'Development';
|
var isDevelopment = process.env.ASPNET_ENV === 'Development';
|
||||||
@@ -13,13 +16,14 @@ module.exports = merge({
|
|||||||
loaders: [
|
loaders: [
|
||||||
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader' },
|
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader' },
|
||||||
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
|
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
|
||||||
{ test: /\.css$/, include: /ClientApp/, loader: 'raw-loader' },
|
{ test: /\.html$/, loader: 'raw-loader' },
|
||||||
{ test: /\.html$/, loader: 'raw-loader' }
|
{ test: /\.css/, include: /bootstrap/, loader: extractVendorCSS.extract(['css']) },
|
||||||
|
{ test: /\.css/, exclude: /bootstrap/, loader: extractSiteCSS.extract(['css']) },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
entry: {
|
entry: {
|
||||||
main: ['./ClientApp/boot-client.ts'],
|
main: ['./ClientApp/boot-client.ts'],
|
||||||
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']
|
vendor: ['angular2/bundles/angular2-polyfills.js', 'bootstrap', 'style-loader', 'jquery', 'angular2/core', 'angular2/common', 'angular2/http', 'angular2/router', 'angular2/platform/browser']
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'wwwroot', 'dist'),
|
path: path.join(__dirname, 'wwwroot', 'dist'),
|
||||||
@@ -29,6 +33,8 @@ module.exports = merge({
|
|||||||
plugins: [
|
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.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
|
||||||
new webpack.optimize.OccurenceOrderPlugin(),
|
new webpack.optimize.OccurenceOrderPlugin(),
|
||||||
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js') // Moves vendor content out of other bundles
|
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'), // Moves vendor content out of other bundles
|
||||||
|
extractSiteCSS,
|
||||||
|
extractVendorCSS
|
||||||
]
|
]
|
||||||
}, isDevelopment ? devConfig : prodConfig);
|
}, isDevelopment ? devConfig : prodConfig);
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
var webpack = require('webpack');
|
var webpack = require('webpack');
|
||||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
||||||
var extractCSS = new ExtractTextPlugin('site.css');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
module: {
|
|
||||||
loaders: [
|
|
||||||
{ test: /\.css/, exclude: /ClientApp/, loader: extractCSS.extract(['css']) },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
plugins: [
|
plugins: [
|
||||||
extractCSS,
|
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
minimize: true,
|
minimize: true,
|
||||||
mangle: false // Due to https://github.com/angular/angular/issues/6678
|
mangle: false // Due to https://github.com/angular/angular/issues/6678
|
||||||
|
|||||||
Reference in New Issue
Block a user