Change WebApplicationBasic template to use web pack vendor DLL and to load CSS as a file (not via JS). Also remove Babel as it's not doing anything here.

This commit is contained in:
SteveSandersonMS
2016-03-01 16:25:37 +00:00
parent 22cebe78d8
commit 0167d5ca3f
8 changed files with 52 additions and 31 deletions

View File

@@ -5,9 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title>
<environment names="Staging,Production">
<link rel="stylesheet" href="~/dist/site.css" />
</environment>
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">

View File

@@ -2,8 +2,6 @@
"name": "WebApplicationBasic",
"version": "0.0.0",
"devDependencies": {
"babel-loader": "^6.2.3",
"babel-preset-es2015": "^6.5.0",
"bootstrap": "^3.3.6",
"css-loader": "^0.23.1",
"extendify": "^1.0.0",
@@ -15,8 +13,5 @@
"typescript": "^1.8.2",
"url-loader": "^0.5.7",
"webpack": "^1.12.14"
},
"dependencies": {
"babel-core": "^6.5.2"
}
}

View File

@@ -42,8 +42,9 @@
"**.vspscc"
],
"scripts": {
"prepublish": [
"prepare": [
"npm install",
"webpack --config webpack.config.vendor.js",
"webpack"
]
}

View File

@@ -1,7 +1,7 @@
{
"compilerOptions": {
"moduleResolution": "node",
"target": "es6",
"target": "es5",
"sourceMap": true
},
"exclude": [

View File

@@ -1,8 +1,3 @@
module.exports = {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.css/, loader: 'style!css' }
]
}
devtool: 'inline-source-map'
};

View File

@@ -1,9 +1,11 @@
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
var devConfig = require('./webpack.config.dev');
var prodConfig = require('./webpack.config.prod');
var isDevelopment = process.env.ASPNET_ENV === 'Development';
var extractCSS = new ExtractTextPlugin('site.css');
module.exports = merge({
resolve: {
@@ -11,14 +13,12 @@ module.exports = merge({
},
module: {
loaders: [
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' },
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'ts-loader' },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
{ test: /\.css/, loader: extractCSS.extract(['css']) }
]
},
entry: {
main: ['./ClientApp/App.ts'],
vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'style-loader', 'jquery']
main: ['./ClientApp/App.ts']
},
output: {
path: path.join(__dirname, 'wwwroot', 'dist'),
@@ -26,8 +26,10 @@ module.exports = merge({
publicPath: '/dist/'
},
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
extractCSS,
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
]
}, isDevelopment ? devConfig : prodConfig);

View File

@@ -1,15 +1,8 @@
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('site.css');
module.exports = {
module: {
loaders: [
{ test: /\.css/, loader: extractCSS.extract(['css']) },
]
},
plugins: [
extractCSS,
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ minimize: true })
]
};

View File

@@ -0,0 +1,36 @@
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('vendor.css');
var isDevelopment = process.env.ASPNET_ENV === 'Development';
module.exports = {
resolve: {
extensions: [ '', '.js' ]
},
module: {
loaders: [
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
{ test: /\.css/, loader: extractCSS.extract(['css']) }
]
},
entry: {
vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'style-loader', 'jquery']
},
output: {
path: path.join(__dirname, 'wwwroot', 'dist'),
filename: '[name].js',
library: '[name]_[hash]',
},
plugins: [
extractCSS,
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.DllPlugin({
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
name: '[name]_[hash]'
})
].concat(isDevelopment ? [] : [
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })
])
};