mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Updated ReactReduxSpa template to match current patterns
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user