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:
SteveSandersonMS
2016-03-01 00:40:37 +00:00
parent f830a5f90a
commit a5509b86e4
9 changed files with 22 additions and 32 deletions

View File

@@ -1,6 +1,9 @@
var path = require('path');
var webpack = require('webpack');
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 prodConfig = require('./webpack.config.prod');
var isDevelopment = process.env.ASPNET_ENV === 'Development';
@@ -13,13 +16,14 @@ module.exports = merge({
loaders: [
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader' },
{ 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: {
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: {
path: path.join(__dirname, 'wwwroot', 'dist'),
@@ -29,6 +33,8 @@ module.exports = merge({
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.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);