Skip to content

Commit 0a961a7

Browse files
Updated ReactReduxSpa template to match current patterns
1 parent a9ce762 commit 0a961a7

File tree

12 files changed

+95
-57
lines changed

12 files changed

+95
-57
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
------------------------------------------------------------------
2+
Don't delete this file. Do include it in your source control repo.
3+
------------------------------------------------------------------
4+
5+
This file exists as a workaround for https://github.com/dotnet/cli/issues/1396
6+
('dotnet publish' does not publish any directories that didn't exist or were
7+
empty before the publish script started).
8+
9+
Hopefully, this can be removed after the move to the new MSBuild.

templates/ReactReduxSpa/ClientApp/routes.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ export default <Route component={ Layout }>
1212
<Route path='(:startDateIndex)' /> { /* Optional route segment that does not affect NavMenu highlighting */ }
1313
</Route>
1414
</Route>;
15+
16+
// Allow Hot Module Reloading
17+
declare var module: any;
18+
if (module.hot) {
19+
module.hot.accept();
20+
}

templates/ReactReduxSpa/ClientApp/store/Counter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const reducer: Reducer<CounterState> = (state, action) => {
3333
if (isActionType(action, IncrementCount)) {
3434
return { count: state.count + 1 };
3535
}
36-
36+
3737
// For unrecognized actions (or in cases where actions have no effect), must return the existing state
3838
// (or default initial state if none was supplied)
3939
return state || { count: 0 };

templates/ReactReduxSpa/Views/Home/Index.cshtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
ViewData["Title"] = "Home Page";
33
}
44

5-
<div id="react-app" asp-prerender-module="ClientApp/boot-server"
6-
asp-prerender-webpack-config="webpack.config.js">Loading...</div>
5+
<div id="react-app" asp-prerender-module="ClientApp/dist/main-server">Loading...</div>
76

87
@section scripts {
9-
<script src="~/dist/main.js" asp-append-version="true"></script>
8+
<script src="~/dist/main-client.js" asp-append-version="true"></script>
109
}

templates/ReactReduxSpa/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"bootstrap": "^3.3.6",
1313
"css-loader": "^0.23.1",
1414
"domain-task": "^2.0.0",
15-
"extendify": "^1.0.0",
1615
"extract-text-webpack-plugin": "^1.0.1",
1716
"file-loader": "^0.8.5",
1817
"jquery": "^2.2.1",
@@ -28,8 +27,9 @@
2827
"ts-loader": "^0.8.1",
2928
"typescript": "^1.8.2",
3029
"url-loader": "^0.5.7",
31-
"webpack-externals-plugin": "^1.0.0",
3230
"webpack": "^1.12.14",
33-
"webpack-hot-middleware": "^2.10.0"
31+
"webpack-externals-plugin": "^1.0.0",
32+
"webpack-hot-middleware": "^2.10.0",
33+
"webpack-merge": "^0.14.1"
3434
}
3535
}

templates/ReactReduxSpa/project.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,20 @@
5151

5252
"publishOptions": {
5353
"include": [
54-
".babelrc",
5554
"appsettings.json",
56-
"ClientApp",
55+
"ClientApp/dist",
5756
"node_modules",
58-
"typings",
5957
"Views",
60-
"tsconfig.json",
61-
"tsd.json",
6258
"web.config",
63-
"webpack.*.js",
6459
"wwwroot"
6560
]
6661
},
6762

6863
"scripts": {
6964
"prepublish": [
7065
"npm install",
71-
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js",
72-
"node node_modules/webpack/bin/webpack.js"
66+
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
67+
"node node_modules/webpack/bin/webpack.js --env.prod"
7368
],
7469
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
7570
},

templates/ReactReduxSpa/template_gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ Obj/
2828

2929
# Visual Studio 2015 cache/options directory
3030
.vs/
31-
/wwwroot/dist/
31+
/wwwroot/dist/**
32+
/ClientApp/dist/**
33+
34+
# Workaround for https://github.com/aspnet/JavaScriptServices/issues/235
35+
!/wwwroot/dist/_placeholder.txt
36+
!/ClientApp/dist/_placeholder.txt
37+
3238

3339
# MSTest test Results
3440
[Tt]est[Rr]esult*/

templates/ReactReduxSpa/webpack.config.dev.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
1+
var isDevBuild = process.argv.indexOf('--env.prod') < 0;
12
var path = require('path');
23
var webpack = require('webpack');
34
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4-
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
5-
var devConfig = require('./webpack.config.dev');
6-
var prodConfig = require('./webpack.config.prod');
7-
var isDevelopment = process.env.ASPNETCORE_ENVIRONMENT === 'Development';
8-
var extractCSS = new ExtractTextPlugin('site.css');
5+
var nodeExternals = require('webpack-node-externals');
6+
var merge = require('webpack-merge');
7+
var allFilenamesExceptJavaScript = /\.(?!js(\?|$))([^.]+(\?|$))/;
98

10-
module.exports = merge({
11-
resolve: {
12-
extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ]
9+
// Configuration in common to both client-side and server-side bundles
10+
var sharedConfig = () => ({
11+
resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] },
12+
output: {
13+
filename: '[name].js',
14+
publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
1315
},
1416
module: {
1517
loaders: [
16-
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' },
17-
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'ts-loader?silent=true' },
18-
{ test: /\.css/, loader: extractCSS.extract(['css']) }
18+
{ test: /\.tsx?$/, include: /ClientApp/, loader: 'babel-loader' },
19+
{ test: /\.tsx?$/, include: /ClientApp/, loader: 'ts', query: { silent: true } }
20+
]
21+
}
22+
});
23+
24+
// Configuration for client-side bundle suitable for running in browsers
25+
var clientBundleConfig = merge(sharedConfig(), {
26+
entry: { 'main-client': './ClientApp/boot-client.tsx' },
27+
module: {
28+
loaders: [
29+
{ test: /\.css$/, loader: ExtractTextPlugin.extract(['css']) },
30+
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url', query: { limit: 25000 } }
1931
]
2032
},
21-
entry: {
22-
main: ['./ClientApp/boot-client.tsx'],
23-
},
24-
output: {
25-
path: path.join(__dirname, 'wwwroot', 'dist'),
26-
filename: '[name].js',
27-
publicPath: '/dist/'
28-
},
33+
output: { path: path.join(__dirname, './wwwroot/dist') },
34+
devtool: isDevBuild ? 'inline-source-map' : null,
2935
plugins: [
30-
extractCSS,
36+
new ExtractTextPlugin('site.css'),
3137
new webpack.DllReferencePlugin({
3238
context: __dirname,
3339
manifest: require('./wwwroot/dist/vendor-manifest.json')
3440
})
35-
]
36-
}, isDevelopment ? devConfig : prodConfig);
41+
].concat(isDevBuild ? [] : [
42+
// Plugins that apply in production builds only
43+
new webpack.optimize.OccurenceOrderPlugin(),
44+
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })
45+
])
46+
});
47+
48+
// Configuration for server-side (prerendering) bundle suitable for running in Node
49+
var serverBundleConfig = merge(sharedConfig(), {
50+
entry: { 'main-server': './ClientApp/boot-server.tsx' },
51+
output: {
52+
libraryTarget: 'commonjs',
53+
path: path.join(__dirname, './ClientApp/dist')
54+
},
55+
target: 'node',
56+
devtool: 'inline-source-map',
57+
externals: [nodeExternals({ whitelist: [allFilenamesExceptJavaScript] })] // Don't bundle .js files from node_modules
58+
});
59+
60+
module.exports = [clientBundleConfig, serverBundleConfig];

templates/ReactReduxSpa/webpack.config.prod.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)