diff --git a/templates/ReactReduxSpa/ClientApp/dist/_placeholder.txt b/templates/ReactReduxSpa/ClientApp/dist/_placeholder.txt new file mode 100644 index 0000000..b22cc15 --- /dev/null +++ b/templates/ReactReduxSpa/ClientApp/dist/_placeholder.txt @@ -0,0 +1,9 @@ +------------------------------------------------------------------ +Don't delete this file. Do include it in your source control repo. +------------------------------------------------------------------ + +This file exists as a workaround for https://github.com/dotnet/cli/issues/1396 +('dotnet publish' does not publish any directories that didn't exist or were +empty before the publish script started). + +Hopefully, this can be removed after the move to the new MSBuild. diff --git a/templates/ReactReduxSpa/ClientApp/routes.tsx b/templates/ReactReduxSpa/ClientApp/routes.tsx index da2f915..1f2406d 100644 --- a/templates/ReactReduxSpa/ClientApp/routes.tsx +++ b/templates/ReactReduxSpa/ClientApp/routes.tsx @@ -12,3 +12,9 @@ export default { /* Optional route segment that does not affect NavMenu highlighting */ } ; + +// Allow Hot Module Reloading +declare var module: any; +if (module.hot) { + module.hot.accept(); +} diff --git a/templates/ReactReduxSpa/ClientApp/store/Counter.ts b/templates/ReactReduxSpa/ClientApp/store/Counter.ts index cf852ab..67eee6b 100644 --- a/templates/ReactReduxSpa/ClientApp/store/Counter.ts +++ b/templates/ReactReduxSpa/ClientApp/store/Counter.ts @@ -33,7 +33,7 @@ export const reducer: Reducer = (state, action) => { if (isActionType(action, IncrementCount)) { return { count: state.count + 1 }; } - + // For unrecognized actions (or in cases where actions have no effect), must return the existing state // (or default initial state if none was supplied) return state || { count: 0 }; diff --git a/templates/ReactReduxSpa/Views/Home/Index.cshtml b/templates/ReactReduxSpa/Views/Home/Index.cshtml index 752d8d9..a53a97e 100644 --- a/templates/ReactReduxSpa/Views/Home/Index.cshtml +++ b/templates/ReactReduxSpa/Views/Home/Index.cshtml @@ -2,9 +2,8 @@ ViewData["Title"] = "Home Page"; } -
Loading...
+
Loading...
@section scripts { - + } diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 6ac0fee..ea162cb 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -12,7 +12,6 @@ "bootstrap": "^3.3.6", "css-loader": "^0.23.1", "domain-task": "^2.0.0", - "extendify": "^1.0.0", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.8.5", "jquery": "^2.2.1", @@ -28,8 +27,9 @@ "ts-loader": "^0.8.1", "typescript": "^1.8.2", "url-loader": "^0.5.7", - "webpack-externals-plugin": "^1.0.0", "webpack": "^1.12.14", - "webpack-hot-middleware": "^2.10.0" + "webpack-externals-plugin": "^1.0.0", + "webpack-hot-middleware": "^2.10.0", + "webpack-merge": "^0.14.1" } } diff --git a/templates/ReactReduxSpa/project.json b/templates/ReactReduxSpa/project.json index 4b1ebfa..2aa0f5d 100755 --- a/templates/ReactReduxSpa/project.json +++ b/templates/ReactReduxSpa/project.json @@ -51,16 +51,11 @@ "publishOptions": { "include": [ - ".babelrc", "appsettings.json", - "ClientApp", + "ClientApp/dist", "node_modules", - "typings", "Views", - "tsconfig.json", - "tsd.json", "web.config", - "webpack.*.js", "wwwroot" ] }, @@ -68,8 +63,8 @@ "scripts": { "prepublish": [ "npm install", - "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js", - "node node_modules/webpack/bin/webpack.js" + "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod", + "node node_modules/webpack/bin/webpack.js --env.prod" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] }, diff --git a/templates/ReactReduxSpa/template_gitignore b/templates/ReactReduxSpa/template_gitignore index 2ee8e59..f8bf5e9 100644 --- a/templates/ReactReduxSpa/template_gitignore +++ b/templates/ReactReduxSpa/template_gitignore @@ -28,7 +28,13 @@ Obj/ # Visual Studio 2015 cache/options directory .vs/ -/wwwroot/dist/ +/wwwroot/dist/** +/ClientApp/dist/** + +# Workaround for https://github.com/aspnet/JavaScriptServices/issues/235 +!/wwwroot/dist/_placeholder.txt +!/ClientApp/dist/_placeholder.txt + # MSTest test Results [Tt]est[Rr]esult*/ diff --git a/templates/ReactReduxSpa/webpack.config.dev.js b/templates/ReactReduxSpa/webpack.config.dev.js deleted file mode 100644 index 719de1f..0000000 --- a/templates/ReactReduxSpa/webpack.config.dev.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - devtool: 'inline-source-map' -}; diff --git a/templates/ReactReduxSpa/webpack.config.js b/templates/ReactReduxSpa/webpack.config.js index 44a2ec4..2d641c7 100644 --- a/templates/ReactReduxSpa/webpack.config.js +++ b/templates/ReactReduxSpa/webpack.config.js @@ -1,36 +1,60 @@ +var isDevBuild = process.argv.indexOf('--env.prod') < 0; 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.ASPNETCORE_ENVIRONMENT === 'Development'; -var extractCSS = new ExtractTextPlugin('site.css'); +var nodeExternals = require('webpack-node-externals'); +var merge = require('webpack-merge'); +var allFilenamesExceptJavaScript = /\.(?!js(\?|$))([^.]+(\?|$))/; -module.exports = merge({ - resolve: { - extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] +// Configuration in common to both client-side and server-side bundles +var sharedConfig = () => ({ + resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] }, + output: { + filename: '[name].js', + publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix }, module: { loaders: [ - { test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' }, - { test: /\.ts(x?)$/, include: /ClientApp/, loader: 'ts-loader?silent=true' }, - { test: /\.css/, loader: extractCSS.extract(['css']) } + { test: /\.tsx?$/, include: /ClientApp/, loader: 'babel-loader' }, + { test: /\.tsx?$/, include: /ClientApp/, loader: 'ts', query: { silent: true } } + ] + } +}); + +// Configuration for client-side bundle suitable for running in browsers +var clientBundleConfig = merge(sharedConfig(), { + entry: { 'main-client': './ClientApp/boot-client.tsx' }, + module: { + loaders: [ + { test: /\.css$/, loader: ExtractTextPlugin.extract(['css']) }, + { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url', query: { limit: 25000 } } ] }, - entry: { - main: ['./ClientApp/boot-client.tsx'], - }, - output: { - path: path.join(__dirname, 'wwwroot', 'dist'), - filename: '[name].js', - publicPath: '/dist/' - }, + output: { path: path.join(__dirname, './wwwroot/dist') }, + devtool: isDevBuild ? 'inline-source-map' : null, plugins: [ - extractCSS, + new ExtractTextPlugin('site.css'), new webpack.DllReferencePlugin({ context: __dirname, manifest: require('./wwwroot/dist/vendor-manifest.json') }) - ] -}, isDevelopment ? devConfig : prodConfig); + ].concat(isDevBuild ? [] : [ + // Plugins that apply in production builds only + new webpack.optimize.OccurenceOrderPlugin(), + new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) + ]) +}); + +// Configuration for server-side (prerendering) bundle suitable for running in Node +var serverBundleConfig = merge(sharedConfig(), { + entry: { 'main-server': './ClientApp/boot-server.tsx' }, + output: { + libraryTarget: 'commonjs', + path: path.join(__dirname, './ClientApp/dist') + }, + target: 'node', + devtool: 'inline-source-map', + externals: [nodeExternals({ whitelist: [allFilenamesExceptJavaScript] })] // Don't bundle .js files from node_modules +}); + +module.exports = [clientBundleConfig, serverBundleConfig]; diff --git a/templates/ReactReduxSpa/webpack.config.prod.js b/templates/ReactReduxSpa/webpack.config.prod.js deleted file mode 100644 index 0731f00..0000000 --- a/templates/ReactReduxSpa/webpack.config.prod.js +++ /dev/null @@ -1,9 +0,0 @@ -var webpack = require('webpack'); - -module.exports = { - plugins: [ - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), - new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }) - ] -}; diff --git a/templates/ReactReduxSpa/webpack.config.vendor.js b/templates/ReactReduxSpa/webpack.config.vendor.js index 8e04124..7e4175a 100644 --- a/templates/ReactReduxSpa/webpack.config.vendor.js +++ b/templates/ReactReduxSpa/webpack.config.vendor.js @@ -1,8 +1,8 @@ +var isDevBuild = process.argv.indexOf('--env.prod') < 0; 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.ASPNETCORE_ENVIRONMENT === 'Development'; module.exports = { resolve: { @@ -10,12 +10,12 @@ module.exports = { }, module: { loaders: [ - { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }, - { test: /\.css/, loader: extractCSS.extract(['css']) } + { 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', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'], + vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'domain-task', 'react', 'react-dom', 'react-router', 'redux', 'redux-thunk', 'react-router-redux', 'redux-typed', 'style-loader', 'jquery'], }, output: { path: path.join(__dirname, 'wwwroot', 'dist'), @@ -29,9 +29,11 @@ module.exports = { new webpack.DllPlugin({ path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), name: '[name]_[hash]' + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' }) - ].concat(isDevelopment ? [] : [ - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), - new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }) + ].concat(isDevBuild ? [] : [ + new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) ]) }; diff --git a/templates/ReactReduxSpa/wwwroot/dist/_placeholder.txt b/templates/ReactReduxSpa/wwwroot/dist/_placeholder.txt new file mode 100644 index 0000000..b22cc15 --- /dev/null +++ b/templates/ReactReduxSpa/wwwroot/dist/_placeholder.txt @@ -0,0 +1,9 @@ +------------------------------------------------------------------ +Don't delete this file. Do include it in your source control repo. +------------------------------------------------------------------ + +This file exists as a workaround for https://github.com/dotnet/cli/issues/1396 +('dotnet publish' does not publish any directories that didn't exist or were +empty before the publish script started). + +Hopefully, this can be removed after the move to the new MSBuild.