Skip to content

Commit 60bcbc4

Browse files
In ReactSpa template, change vendor bundle to be a prebuilt DLL (for faster builds)
1 parent 8a5e58a commit 60bcbc4

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

templates/ReactSpa/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - WebApplicationBasic</title>
77

8+
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
89
<environment names="Staging,Production">
9-
<link rel="stylesheet" href="~/dist/site.css" />
10+
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
1011
</environment>
1112
</head>
1213
<body>

templates/ReactSpa/project.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
"**.vspscc"
4444
],
4545
"scripts": {
46-
"prepublish": [
46+
"prepare": [
4747
"npm install",
48+
"webpack --config webpack.config.vendor.js"
49+
],
50+
"prepublish": [
4851
"webpack"
4952
]
5053
}

templates/ReactSpa/webpack.config.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ module.exports = merge({
1212
module: {
1313
loaders: [
1414
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' },
15-
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'ts-loader' },
16-
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
15+
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'ts-loader' }
1716
]
1817
},
1918
entry: {
2019
main: ['./ClientApp/boot.tsx'],
21-
vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery']
2220
},
2321
output: {
2422
path: path.join(__dirname, 'wwwroot', 'dist'),
2523
filename: '[name].js',
2624
publicPath: '/dist/'
2725
},
2826
plugins: [
29-
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
30-
new webpack.optimize.OccurenceOrderPlugin(),
31-
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js') // Moves vendor content out of other bundles
27+
new webpack.DllReferencePlugin({
28+
context: __dirname,
29+
manifest: require('./wwwroot/dist/vendor-manifest.json')
30+
})
3231
]
3332
}, isDevelopment ? devConfig : prodConfig);

templates/ReactSpa/webpack.config.prod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
},
1111
plugins: [
1212
extractCSS,
13+
new webpack.optimize.OccurenceOrderPlugin(),
1314
new webpack.optimize.UglifyJsPlugin({ minimize: true })
1415
]
1516
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var path = require('path');
2+
var webpack = require('webpack');
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
var extractCSS = new ExtractTextPlugin('vendor.css');
5+
6+
module.exports = {
7+
resolve: {
8+
extensions: [ '', '.js' ]
9+
},
10+
module: {
11+
loaders: [
12+
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
13+
{ test: /\.css/, loader: extractCSS.extract(['css']) }
14+
]
15+
},
16+
entry: {
17+
vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'],
18+
},
19+
output: {
20+
path: path.join(__dirname, 'wwwroot', 'dist'),
21+
filename: '[name].js',
22+
library: '[name]_[hash]',
23+
},
24+
plugins: [
25+
extractCSS,
26+
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
27+
new webpack.optimize.OccurenceOrderPlugin(),
28+
new webpack.DllPlugin({
29+
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
30+
name: '[name]_[hash]'
31+
})
32+
]
33+
};

0 commit comments

Comments
 (0)