diff --git a/templates/Angular2Spa/package.json b/templates/Angular2Spa/package.json index 04ab09b4..45bf9575 100644 --- a/templates/Angular2Spa/package.json +++ b/templates/Angular2Spa/package.json @@ -21,28 +21,27 @@ "angular2-universal-polyfills": "~2.0.11", "aspnet-prerendering": "^2.0.0", "aspnet-webpack": "^1.0.17", + "awesome-typescript-loader": "3.0.0-beta.13 || ^3.0.0", "bootstrap": "^3.3.7", "css": "^2.2.1", "css-loader": "^0.25.0", "es6-shim": "^0.35.1", "event-source-polyfill": "^0.0.7", "expose-loader": "^0.7.1", - "extract-text-webpack-plugin": "^1.0.1", + "extract-text-webpack-plugin": "^2.0.0-rc", "file-loader": "^0.9.0", "html-loader": "^0.4.4", "isomorphic-fetch": "^2.2.1", "jquery": "^2.2.1", "json-loader": "^0.5.4", - "node-noop": "^1.0.0", "preboot": "^4.5.2", "raw-loader": "^0.5.1", "rxjs": "5.0.0-beta.12", "style-loader": "^0.13.1", "to-string-loader": "^1.1.5", - "ts-loader": "^0.8.2", "typescript": "^2.0.3", "url-loader": "^0.5.7", - "webpack": "^1.13.2", + "webpack": "^2.2.0", "webpack-hot-middleware": "^2.12.2", "webpack-merge": "^0.14.1", "zone.js": "^0.6.25" diff --git a/templates/Angular2Spa/webpack.config.js b/templates/Angular2Spa/webpack.config.js index b54b08d3..3cfc02ca 100644 --- a/templates/Angular2Spa/webpack.config.js +++ b/templates/Angular2Spa/webpack.config.js @@ -1,68 +1,71 @@ -var isDevBuild = process.argv.indexOf('--env.prod') < 0; -var path = require('path'); -var webpack = require('webpack'); -var merge = require('webpack-merge'); +const path = require('path'); +const webpack = require('webpack'); +const merge = require('webpack-merge'); +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; -// Configuration in common to both client-side and server-side bundles -var sharedConfig = { - context: __dirname, - resolve: { extensions: [ '', '.js', '.ts' ] }, - output: { - filename: '[name].js', - publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix - }, - module: { - loaders: [ - { test: /\.ts$/, include: /ClientApp/, loaders: ['ts-loader?silent=true', 'angular2-template-loader'] }, - { test: /\.html$/, loader: 'html-loader?minimize=false' }, - { test: /\.css$/, loader: 'to-string-loader!css-loader' }, - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }, - { test: /\.json$/, loader: 'json-loader' } - ] - } -}; +module.exports = (env) => { + // Configuration in common to both client-side and server-side bundles + const isDevBuild = !(env && env.prod); + const sharedConfig = { + stats: { modules: false }, + context: __dirname, + resolve: { extensions: [ '.js', '.ts' ] }, + output: { + filename: '[name].js', + publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix + }, + module: { + rules: [ + { test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] }, + { test: /\.html$/, use: 'html-loader?minimize=false' }, + { test: /\.css$/, use: ['to-string-loader', 'css-loader'] }, + { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' } + ] + }, + plugins: [new CheckerPlugin()] + }; -// Configuration for client-side bundle suitable for running in browsers -var clientBundleOutputDir = './wwwroot/dist'; -var clientBundleConfig = merge(sharedConfig, { - entry: { 'main-client': './ClientApp/boot-client.ts' }, - output: { path: path.join(__dirname, clientBundleOutputDir) }, - plugins: [ - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./wwwroot/dist/vendor-manifest.json') - }) - ].concat(isDevBuild ? [ - // Plugins that apply in development builds only - new webpack.SourceMapDevToolPlugin({ - filename: '[file].map', // Remove this line if you prefer inline source maps - moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk - }) - ] : [ - // Plugins that apply in production builds only - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin() - ]) -}); + // Configuration for client-side bundle suitable for running in browsers + const clientBundleOutputDir = './wwwroot/dist'; + const clientBundleConfig = merge(sharedConfig, { + entry: { 'main-client': './ClientApp/boot-client.ts' }, + output: { path: path.join(__dirname, clientBundleOutputDir) }, + plugins: [ + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./wwwroot/dist/vendor-manifest.json') + }) + ].concat(isDevBuild ? [ + // Plugins that apply in development builds only + new webpack.SourceMapDevToolPlugin({ + filename: '[file].map', // Remove this line if you prefer inline source maps + moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk + }) + ] : [ + // Plugins that apply in production builds only + new webpack.optimize.UglifyJsPlugin() + ]) + }); -// Configuration for server-side (prerendering) bundle suitable for running in Node -var serverBundleConfig = merge(sharedConfig, { - resolve: { packageMains: ['main'] }, - entry: { 'main-server': './ClientApp/boot-server.ts' }, - plugins: [ - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./ClientApp/dist/vendor-manifest.json'), - sourceType: 'commonjs2', - name: './vendor' - }) - ], - output: { - libraryTarget: 'commonjs', - path: path.join(__dirname, './ClientApp/dist') - }, - target: 'node', - devtool: 'inline-source-map' -}); + // Configuration for server-side (prerendering) bundle suitable for running in Node + const serverBundleConfig = merge(sharedConfig, { + resolve: { mainFields: ['main'] }, + entry: { 'main-server': './ClientApp/boot-server.ts' }, + plugins: [ + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./ClientApp/dist/vendor-manifest.json'), + sourceType: 'commonjs2', + name: './vendor' + }) + ], + output: { + libraryTarget: 'commonjs', + path: path.join(__dirname, './ClientApp/dist') + }, + target: 'node', + devtool: 'inline-source-map' + }); -module.exports = [clientBundleConfig, serverBundleConfig]; + return [clientBundleConfig, serverBundleConfig]; +}; diff --git a/templates/Angular2Spa/webpack.config.vendor.js b/templates/Angular2Spa/webpack.config.vendor.js index c5c9c35c..35318959 100644 --- a/templates/Angular2Spa/webpack.config.vendor.js +++ b/templates/Angular2Spa/webpack.config.vendor.js @@ -1,88 +1,88 @@ -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('webpack-merge'); -var extractCSS = new ExtractTextPlugin('vendor.css'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const merge = require('webpack-merge'); -var sharedConfig = { - resolve: { extensions: [ '', '.js' ] }, - module: { - loaders: [ - { test: /\.json$/, loader: require.resolve('json-loader') }, - { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, loader: 'url-loader?limit=100000' } +module.exports = (env) => { + const extractCSS = new ExtractTextPlugin('vendor.css'); + const isDevBuild = !(env && env.prod); + const sharedConfig = { + stats: { modules: false }, + resolve: { extensions: [ '.js' ] }, + module: { + rules: [ + { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' } + ] + }, + entry: { + vendor: [ + '@angular/common', + '@angular/compiler', + '@angular/core', + '@angular/http', + '@angular/platform-browser', + '@angular/platform-browser-dynamic', + '@angular/router', + '@angular/platform-server', + 'angular2-universal', + 'angular2-universal-polyfills', + 'bootstrap', + 'bootstrap/dist/css/bootstrap.css', + 'es6-shim', + 'es6-promise', + 'event-source-polyfill', + 'jquery', + 'zone.js', + ] + }, + output: { + publicPath: '/dist/', + filename: '[name].js', + library: '[name]_[hash]' + }, + 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.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580 + new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100 ] - }, - entry: { - vendor: [ - '@angular/common', - '@angular/compiler', - '@angular/core', - '@angular/http', - '@angular/platform-browser', - '@angular/platform-browser-dynamic', - '@angular/router', - '@angular/platform-server', - 'angular2-universal', - 'angular2-universal-polyfills', - 'bootstrap', - 'bootstrap/dist/css/bootstrap.css', - 'es6-shim', - 'es6-promise', - 'event-source-polyfill', - 'jquery', - 'zone.js', - ] - }, - output: { - publicPath: '/dist/', - filename: '[name].js', - library: '[name]_[hash]' - }, - 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.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580 - new webpack.IgnorePlugin(/^vertx$/), // Workaround for https://github.com/stefanpenner/es6-promise/issues/100 - new webpack.NormalModuleReplacementPlugin(/\/iconv-loader$/, require.resolve('node-noop')), // Workaround for https://github.com/andris9/encoding/issues/16 - ] -}; + }; -var clientBundleConfig = merge(sharedConfig, { - output: { path: path.join(__dirname, 'wwwroot', 'dist') }, - module: { - loaders: [ - { test: /\.css(\?|$)/, loader: extractCSS.extract(['css-loader']) } - ] - }, - plugins: [ - extractCSS, - new webpack.DllPlugin({ - path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), - name: '[name]_[hash]' - }) - ].concat(isDevBuild ? [] : [ - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) - ]) -}); + const clientBundleConfig = merge(sharedConfig, { + output: { path: path.join(__dirname, 'wwwroot', 'dist') }, + module: { + rules: [ + { test: /\.css(\?|$)/, use: extractCSS.extract({ loader: 'css-loader' }) } + ] + }, + plugins: [ + extractCSS, + new webpack.DllPlugin({ + path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }) + ].concat(isDevBuild ? [] : [ + new webpack.optimize.UglifyJsPlugin() + ]) + }); -var serverBundleConfig = merge(sharedConfig, { - target: 'node', - resolve: { packageMains: ['main'] }, - output: { - path: path.join(__dirname, 'ClientApp', 'dist'), - libraryTarget: 'commonjs2', - }, - module: { - loaders: [ { test: /\.css(\?|$)/, loader: 'to-string-loader!css-loader' } ] - }, - entry: { vendor: ['aspnet-prerendering'] }, - plugins: [ - new webpack.DllPlugin({ - path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), - name: '[name]_[hash]' - }) - ] -}); + const serverBundleConfig = merge(sharedConfig, { + target: 'node', + resolve: { mainFields: ['main'] }, + output: { + path: path.join(__dirname, 'ClientApp', 'dist'), + libraryTarget: 'commonjs2', + }, + module: { + rules: [ { test: /\.css(\?|$)/, use: ['to-string-loader', 'css-loader'] } ] + }, + entry: { vendor: ['aspnet-prerendering'] }, + plugins: [ + new webpack.DllPlugin({ + path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }) + ] + }); -module.exports = [clientBundleConfig, serverBundleConfig]; + return [clientBundleConfig, serverBundleConfig]; +} diff --git a/templates/KnockoutSpa/package.json b/templates/KnockoutSpa/package.json index ed36fd91..8b5ead87 100644 --- a/templates/KnockoutSpa/package.json +++ b/templates/KnockoutSpa/package.json @@ -12,13 +12,14 @@ "@types/requirejs": "^2.1.26", "@types/signals": "0.0.16", "@types/whatwg-fetch": "0.0.30", - "aspnet-webpack": "^1.0.17", + "aspnet-webpack": "^1.0.27", + "awesome-typescript-loader": "3.0.0-beta.13 || ^3.0.0", "bootstrap": "^3.3.6", "bundle-loader": "^0.5.4", "crossroads": "^0.12.2", "css-loader": "^0.25.0", "event-source-polyfill": "^0.0.7", - "extract-text-webpack-plugin": "^1.0.1", + "extract-text-webpack-plugin": "^2.0.0-rc", "file-loader": "^0.9.0", "history": "^4.3.0", "isomorphic-fetch": "^2.2.1", @@ -27,10 +28,9 @@ "knockout": "^3.4.0", "raw-loader": "^0.5.1", "style-loader": "^0.13.1", - "ts-loader": "^0.8.2", "typescript": "^2.0.3", "url-loader": "^0.5.7", - "webpack": "^1.13.2", + "webpack": "^2.2.0", "webpack-hot-middleware": "^2.12.2" } } diff --git a/templates/KnockoutSpa/webpack.config.js b/templates/KnockoutSpa/webpack.config.js index 829a1de6..281b286d 100644 --- a/templates/KnockoutSpa/webpack.config.js +++ b/templates/KnockoutSpa/webpack.config.js @@ -1,41 +1,44 @@ -var isDevBuild = process.argv.indexOf('--env.prod') < 0; -var path = require('path'); -var webpack = require('webpack'); -var ExtractTextPlugin = require('extract-text-webpack-plugin'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; +const bundleOutputDir = './wwwroot/dist'; -var bundleOutputDir = './wwwroot/dist'; -module.exports = { - entry: { 'main': './ClientApp/boot.ts' }, - resolve: { extensions: [ '', '.js', '.ts' ] }, - output: { - path: path.join(__dirname, bundleOutputDir), - filename: '[name].js', - publicPath: '/dist/' - }, - module: { - loaders: [ - { test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, - { test: /\.html$/, loader: 'raw-loader' }, - { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract(['css-loader']) }, - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }, - { test: /\.json$/, loader: 'json-loader' } - ] - }, - plugins: [ - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./wwwroot/dist/vendor-manifest.json') - }) - ].concat(isDevBuild ? [ - // Plugins that apply in development builds only - new webpack.SourceMapDevToolPlugin({ - filename: '[file].map', // Remove this line if you prefer inline source maps - moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk - }) - ] : [ - // Plugins that apply in production builds only - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), - new ExtractTextPlugin('site.css') - ]) +module.exports = (env) => { + const isDevBuild = !(env && env.prod); + return [{ + stats: { modules: false }, + entry: { 'main': './ClientApp/boot.ts' }, + resolve: { extensions: [ '.js', '.ts' ] }, + output: { + path: path.join(__dirname, bundleOutputDir), + filename: '[name].js', + publicPath: '/dist/' + }, + module: { + rules: [ + { test: /\.ts$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' }, + { test: /\.html$/, loader: 'raw-loader' }, + { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ loader: 'css-loader' }) }, + { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader?limit=25000' } + ] + }, + plugins: [ + new CheckerPlugin(), + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./wwwroot/dist/vendor-manifest.json') + }) + ].concat(isDevBuild ? [ + // Plugins that apply in development builds only + new webpack.SourceMapDevToolPlugin({ + filename: '[file].map', // Remove this line if you prefer inline source maps + moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk + }) + ] : [ + // Plugins that apply in production builds only + new webpack.optimize.UglifyJsPlugin(), + new ExtractTextPlugin('site.css') + ]) + }]; }; diff --git a/templates/KnockoutSpa/webpack.config.vendor.js b/templates/KnockoutSpa/webpack.config.vendor.js index a7591480..710459e5 100644 --- a/templates/KnockoutSpa/webpack.config.vendor.js +++ b/templates/KnockoutSpa/webpack.config.vendor.js @@ -1,37 +1,39 @@ -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'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); -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-loader']) } - ] - }, - entry: { - vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'knockout', 'crossroads', 'event-source-polyfill', 'history', 'isomorphic-fetch', 'style-loader', 'jquery'], - }, - output: { - path: path.join(__dirname, 'wwwroot', 'dist'), - publicPath: '/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(isDevBuild ? [] : [ - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) - ]) +module.exports = (env) => { + const isDevBuild = !(env && env.prod); + const extractCSS = new ExtractTextPlugin('vendor.css'); + return [{ + stats: { modules: false }, + resolve: { + extensions: [ '.js' ] + }, + module: { + rules: [ + { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }, + { test: /\.css(\?|$)/, use: extractCSS.extract({ loader: 'css-loader' }) } + ] + }, + entry: { + vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'knockout', 'crossroads', 'event-source-polyfill', 'history', 'isomorphic-fetch', 'style-loader', 'jquery'], + }, + output: { + path: path.join(__dirname, 'wwwroot', 'dist'), + publicPath: '/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.DllPlugin({ + path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }) + ].concat(isDevBuild ? [] : [ + new webpack.optimize.UglifyJsPlugin() + ]) + }]; }; diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 11aef6f2..a3db4cf5 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -9,14 +9,13 @@ "@types/react-router": "^2.0.30", "@types/react-router-redux": "^4.0.30", "@types/redux": "3.5.27", - "@types/source-map": "^0.1.28", - "@types/uglify-js": "^2.0.27", - "@types/webpack": "^1.12.35", - "@types/webpack-env": "^1.12.1", + "@types/webpack": "^2.2.0", + "@types/webpack-env": "^1.13.0", "@types/whatwg-fetch": "0.0.28", "aspnet-prerendering": "^2.0.0", - "aspnet-webpack": "^1.0.17", - "aspnet-webpack-react": "^1.0.2", + "aspnet-webpack": "^1.0.27", + "aspnet-webpack-react": "^1.0.4", + "awesome-typescript-loader": "3.0.0-beta.13 || ^3.0.0", "babel-core": "^6.5.2", "babel-loader": "^6.2.3", "babel-preset-es2015": "^6.5.0", @@ -25,7 +24,7 @@ "css-loader": "^0.23.1", "domain-task": "^2.0.1", "event-source-polyfill": "^0.0.7", - "extract-text-webpack-plugin": "^1.0.1", + "extract-text-webpack-plugin": "^2.0.0-rc", "file-loader": "^0.8.5", "jquery": "^2.2.1", "json-loader": "^0.5.4", @@ -38,10 +37,9 @@ "redux": "^3.6.0", "redux-thunk": "^2.2.0", "style-loader": "^0.13.0", - "ts-loader": "^0.8.1", "typescript": "^2.0.3", "url-loader": "^0.5.7", - "webpack": "^1.13.2", + "webpack": "^2.2.0", "webpack-hot-middleware": "^2.12.2", "webpack-merge": "^0.14.1" } diff --git a/templates/ReactReduxSpa/webpack.config.js b/templates/ReactReduxSpa/webpack.config.js index d079e5c3..a88ff551 100644 --- a/templates/ReactReduxSpa/webpack.config.js +++ b/templates/ReactReduxSpa/webpack.config.js @@ -1,73 +1,77 @@ -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('webpack-merge'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; +const merge = require('webpack-merge'); -// 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: /\.tsx?$/, include: /ClientApp/, loader: 'babel-loader' }, - { test: /\.tsx?$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, - { test: /\.json$/, loader: 'json-loader' } - ] - } -}); +module.exports = (env) => { + const isDevBuild = !(env && env.prod); -// Configuration for client-side bundle suitable for running in browsers -var clientBundleOutputDir = './wwwroot/dist'; -var clientBundleConfig = merge(sharedConfig(), { - entry: { 'main-client': './ClientApp/boot-client.tsx' }, - module: { - loaders: [ - { test: /\.css$/, loader: ExtractTextPlugin.extract(['css-loader']) }, - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } } - ] - }, - output: { path: path.join(__dirname, clientBundleOutputDir) }, - plugins: [ - new ExtractTextPlugin('site.css'), - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./wwwroot/dist/vendor-manifest.json') - }) - ].concat(isDevBuild ? [ - // Plugins that apply in development builds only - new webpack.SourceMapDevToolPlugin({ - filename: '[file].map', // Remove this line if you prefer inline source maps - moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk - }) - ] : [ - // Plugins that apply in production builds only - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) - ]) -}); + // Configuration in common to both client-side and server-side bundles + const sharedConfig = () => ({ + stats: { modules: false }, + resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] }, + output: { + filename: '[name].js', + publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix + }, + module: { + rules: [ + { test: /\.tsx?$/, include: /ClientApp/, use: 'babel-loader' }, + { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' } + ] + }, + plugins: [new CheckerPlugin()] + }); -// Configuration for server-side (prerendering) bundle suitable for running in Node -var serverBundleConfig = merge(sharedConfig(), { - resolve: { packageMains: ['main'] }, - entry: { 'main-server': './ClientApp/boot-server.tsx' }, - plugins: [ - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./ClientApp/dist/vendor-manifest.json'), - sourceType: 'commonjs2', - name: './vendor' - }) - ], - output: { - libraryTarget: 'commonjs', - path: path.join(__dirname, './ClientApp/dist') - }, - target: 'node', - devtool: 'inline-source-map' -}); + // Configuration for client-side bundle suitable for running in browsers + const clientBundleOutputDir = './wwwroot/dist'; + const clientBundleConfig = merge(sharedConfig(), { + entry: { 'main-client': './ClientApp/boot-client.tsx' }, + module: { + rules: [ + { test: /\.css$/, use: ExtractTextPlugin.extract({ loader: 'css-loader' }) }, + { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' } + ] + }, + output: { path: path.join(__dirname, clientBundleOutputDir) }, + plugins: [ + new ExtractTextPlugin('site.css'), + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./wwwroot/dist/vendor-manifest.json') + }) + ].concat(isDevBuild ? [ + // Plugins that apply in development builds only + new webpack.SourceMapDevToolPlugin({ + filename: '[file].map', // Remove this line if you prefer inline source maps + moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk + }) + ] : [ + // Plugins that apply in production builds only + new webpack.optimize.UglifyJsPlugin() + ]) + }); -module.exports = [clientBundleConfig, serverBundleConfig]; + // Configuration for server-side (prerendering) bundle suitable for running in Node + const serverBundleConfig = merge(sharedConfig(), { + resolve: { mainFields: ['main'] }, + entry: { 'main-server': './ClientApp/boot-server.tsx' }, + plugins: [ + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./ClientApp/dist/vendor-manifest.json'), + sourceType: 'commonjs2', + name: './vendor' + }) + ], + output: { + libraryTarget: 'commonjs', + path: path.join(__dirname, './ClientApp/dist') + }, + target: 'node', + devtool: 'inline-source-map' + }); + + return [clientBundleConfig, serverBundleConfig]; +}; diff --git a/templates/ReactReduxSpa/webpack.config.vendor.js b/templates/ReactReduxSpa/webpack.config.vendor.js index f680868c..b2221331 100644 --- a/templates/ReactReduxSpa/webpack.config.vendor.js +++ b/templates/ReactReduxSpa/webpack.config.vendor.js @@ -1,85 +1,87 @@ -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('webpack-merge'); -var extractCSS = new ExtractTextPlugin('vendor.css'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const merge = require('webpack-merge'); -var sharedConfig = { - resolve: { extensions: [ '', '.js' ] }, - module: { - loaders: [ - { test: /\.json$/, loader: require.resolve('json-loader') }, - { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, loader: 'url-loader?limit=100000' } - ] - }, - entry: { - vendor: [ - 'bootstrap', - 'bootstrap/dist/css/bootstrap.css', - 'domain-task', - 'event-source-polyfill', - 'react', - 'react-dom', - 'react-router', - 'react-redux', - 'redux', - 'redux-thunk', - 'react-router-redux', - 'style-loader', - 'jquery' - ], - }, - output: { - publicPath: '/dist/', - filename: '[name].js', - library: '[name]_[hash]', - }, - 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.NormalModuleReplacementPlugin(/\/iconv-loader$/, require.resolve('node-noop')), // Workaround for https://github.com/andris9/encoding/issues/16 - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' - }) - ] -}; +module.exports = (env) => { + const isDevBuild = !(env && env.prod); + const extractCSS = new ExtractTextPlugin('vendor.css'); -var clientBundleConfig = merge(sharedConfig, { - output: { path: path.join(__dirname, 'wwwroot', 'dist') }, - module: { - loaders: [ - { test: /\.css(\?|$)/, loader: extractCSS.extract(['css-loader']) } + const sharedConfig = { + stats: { modules: false }, + resolve: { extensions: [ '.js' ] }, + module: { + rules: [ + { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' } + ] + }, + entry: { + vendor: [ + 'bootstrap', + 'bootstrap/dist/css/bootstrap.css', + 'domain-task', + 'event-source-polyfill', + 'react', + 'react-dom', + 'react-router', + 'react-redux', + 'redux', + 'redux-thunk', + 'react-router-redux', + 'style-loader', + 'jquery' + ], + }, + output: { + publicPath: '/dist/', + filename: '[name].js', + library: '[name]_[hash]', + }, + 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.NormalModuleReplacementPlugin(/\/iconv-loader$/, require.resolve('node-noop')), // Workaround for https://github.com/andris9/encoding/issues/16 + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' + }) ] - }, - plugins: [ - extractCSS, - new webpack.DllPlugin({ - path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), - name: '[name]_[hash]' - }) - ].concat(isDevBuild ? [] : [ - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) - ]) -}); + }; -var serverBundleConfig = merge(sharedConfig, { - target: 'node', - resolve: { packageMains: ['main'] }, - output: { - path: path.join(__dirname, 'ClientApp', 'dist'), - libraryTarget: 'commonjs2', - }, - module: { - loaders: [ { test: /\.css(\?|$)/, loader: 'css-loader' } ] - }, - entry: { vendor: ['aspnet-prerendering', 'react-dom/server'] }, - plugins: [ - new webpack.DllPlugin({ - path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), - name: '[name]_[hash]' - }) - ] -}); + const clientBundleConfig = merge(sharedConfig, { + output: { path: path.join(__dirname, 'wwwroot', 'dist') }, + module: { + rules: [ + { test: /\.css(\?|$)/, use: extractCSS.extract({ loader: 'css-loader' }) } + ] + }, + plugins: [ + extractCSS, + new webpack.DllPlugin({ + path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }) + ].concat(isDevBuild ? [] : [ + new webpack.optimize.UglifyJsPlugin() + ]) + }); -module.exports = [clientBundleConfig, serverBundleConfig]; + const serverBundleConfig = merge(sharedConfig, { + target: 'node', + resolve: { mainFields: ['main'] }, + output: { + path: path.join(__dirname, 'ClientApp', 'dist'), + libraryTarget: 'commonjs2', + }, + module: { + rules: [ { test: /\.css(\?|$)/, use: 'css-loader' } ] + }, + entry: { vendor: ['aspnet-prerendering', 'react-dom/server'] }, + plugins: [ + new webpack.DllPlugin({ + path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }) + ] + }); + + return [clientBundleConfig, serverBundleConfig]; +}; diff --git a/templates/ReactSpa/package.json b/templates/ReactSpa/package.json index 79b89c0c..ba8611ff 100644 --- a/templates/ReactSpa/package.json +++ b/templates/ReactSpa/package.json @@ -7,8 +7,9 @@ "@types/react": "^0.14.38", "@types/react-dom": "^0.14.17", "@types/react-router": "^2.0.38", - "aspnet-webpack": "^1.0.17", - "aspnet-webpack-react": "^1.0.2", + "aspnet-webpack": "^1.0.27", + "aspnet-webpack-react": "^1.0.4", + "awesome-typescript-loader": "3.0.0-beta.13 || ^3.0.0", "babel-core": "^6.17.0", "babel-loader": "^6.2.5", "babel-preset-es2015": "^6.16.0", @@ -16,7 +17,7 @@ "bootstrap": "^3.3.6", "css-loader": "^0.25.0", "event-source-polyfill": "^0.0.7", - "extract-text-webpack-plugin": "^1.0.1", + "extract-text-webpack-plugin": "^2.0.0-rc", "file-loader": "^0.9.0", "isomorphic-fetch": "^2.2.1", "jquery": "^2.2.1", @@ -25,10 +26,9 @@ "react-dom": "^15.3.2", "react-router": "^2.8.1", "style-loader": "^0.13.1", - "ts-loader": "^0.8.2", "typescript": "^2.0.3", "url-loader": "^0.5.7", - "webpack": "^1.13.2", + "webpack": "^2.2.0", "webpack-hot-middleware": "^2.12.2" } } diff --git a/templates/ReactSpa/webpack.config.js b/templates/ReactSpa/webpack.config.js index 6d6c593e..2831bcbf 100644 --- a/templates/ReactSpa/webpack.config.js +++ b/templates/ReactSpa/webpack.config.js @@ -1,42 +1,44 @@ -var isDevBuild = process.argv.indexOf('--env.prod') < 0; -var path = require('path'); -var webpack = require('webpack'); -var ExtractTextPlugin = require('extract-text-webpack-plugin'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; +const bundleOutputDir = './wwwroot/dist'; -var bundleOutputDir = './wwwroot/dist'; -module.exports = { - devtool: isDevBuild ? 'inline-source-map' : null, - entry: { 'main': './ClientApp/boot.tsx' }, - resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] }, - output: { - path: path.join(__dirname, bundleOutputDir), - filename: '[name].js', - publicPath: '/dist/' - }, - module: { - loaders: [ - { test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' }, - { test: /\.tsx?$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, - { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract(['css-loader']) }, - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }, - { test: /\.json$/, loader: 'json-loader' } - ] - }, - plugins: [ - new webpack.DllReferencePlugin({ - context: __dirname, - manifest: require('./wwwroot/dist/vendor-manifest.json') - }) - ].concat(isDevBuild ? [ - // Plugins that apply in development builds only - new webpack.SourceMapDevToolPlugin({ - filename: '[file].map', // Remove this line if you prefer inline source maps - moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk - }) - ] : [ - // Plugins that apply in production builds only - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), - new ExtractTextPlugin('site.css') - ]) +module.exports = (env) => { + const isDevBuild = !(env && env.prod); + return [{ + stats: { modules: false }, + entry: { 'main': './ClientApp/boot.tsx' }, + resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] }, + output: { + path: path.join(__dirname, bundleOutputDir), + filename: '[name].js', + publicPath: '/dist/' + }, + module: { + rules: [ + { test: /\.ts(x?)$/, include: /ClientApp/, use: 'babel-loader' }, + { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' }, + { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ loader: 'css-loader' }) }, + { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' } + ] + }, + plugins: [ + new CheckerPlugin(), + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./wwwroot/dist/vendor-manifest.json') + }) + ].concat(isDevBuild ? [ + // Plugins that apply in development builds only + new webpack.SourceMapDevToolPlugin({ + filename: '[file].map', // Remove this line if you prefer inline source maps + moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk + }) + ] : [ + // Plugins that apply in production builds only + new webpack.optimize.UglifyJsPlugin(), + new ExtractTextPlugin('site.css') + ]) + }]; }; diff --git a/templates/ReactSpa/webpack.config.vendor.js b/templates/ReactSpa/webpack.config.vendor.js index f9822226..66933625 100644 --- a/templates/ReactSpa/webpack.config.vendor.js +++ b/templates/ReactSpa/webpack.config.vendor.js @@ -1,40 +1,42 @@ -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'); +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); -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-loader']) } - ] - }, - entry: { - vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'event-source-polyfill', 'isomorphic-fetch', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'], - }, - output: { - path: path.join(__dirname, 'wwwroot', 'dist'), - publicPath: '/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]' - }), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' - }) - ].concat(isDevBuild ? [] : [ - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) - ]) +module.exports = (env) => { + const extractCSS = new ExtractTextPlugin('vendor.css'); + const isDevBuild = !(env && env.prod); + return [{ + stats: { modules: false }, + resolve: { + extensions: [ '.js' ] + }, + module: { + rules: [ + { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }, + { test: /\.css(\?|$)/, use: extractCSS.extract(['css-loader']) } + ] + }, + entry: { + vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'event-source-polyfill', 'isomorphic-fetch', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'], + }, + output: { + path: path.join(__dirname, 'wwwroot', 'dist'), + publicPath: '/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.DllPlugin({ + path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), + name: '[name]_[hash]' + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' + }) + ].concat(isDevBuild ? [] : [ + new webpack.optimize.UglifyJsPlugin() + ]) + }]; };