|
| 1 | +var isDevBuild = process.argv.indexOf('--env.prod') < 0; |
1 | 2 | var path = require('path'); |
2 | 3 | var webpack = require('webpack'); |
3 | 4 | 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(\?|$))([^.]+(\?|$))/; |
9 | 8 |
|
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 |
13 | 15 | }, |
14 | 16 | module: { |
15 | 17 | 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 } } |
19 | 31 | ] |
20 | 32 | }, |
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, |
29 | 35 | plugins: [ |
30 | | - extractCSS, |
| 36 | + new ExtractTextPlugin('site.css'), |
31 | 37 | new webpack.DllReferencePlugin({ |
32 | 38 | context: __dirname, |
33 | 39 | manifest: require('./wwwroot/dist/vendor-manifest.json') |
34 | 40 | }) |
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]; |
0 commit comments