|
1 | | -var isDevBuild = process.argv.indexOf('--env.prod') < 0; |
2 | | -var path = require('path'); |
3 | | -var webpack = require('webpack'); |
4 | | -var ExtractTextPlugin = require('extract-text-webpack-plugin'); |
5 | | -var merge = require('webpack-merge'); |
| 1 | +const path = require('path'); |
| 2 | +const webpack = require('webpack'); |
| 3 | +const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 4 | +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; |
| 5 | +const merge = require('webpack-merge'); |
6 | 6 |
|
7 | | -// Configuration in common to both client-side and server-side bundles |
8 | | -var sharedConfig = () => ({ |
9 | | - resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] }, |
10 | | - output: { |
11 | | - filename: '[name].js', |
12 | | - publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix |
13 | | - }, |
14 | | - module: { |
15 | | - loaders: [ |
16 | | - { test: /\.tsx?$/, include: /ClientApp/, loader: 'babel-loader' }, |
17 | | - { test: /\.tsx?$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, |
18 | | - { test: /\.json$/, loader: 'json-loader' } |
19 | | - ] |
20 | | - } |
21 | | -}); |
| 7 | +module.exports = (env) => { |
| 8 | + const isDevBuild = !(env && env.prod); |
22 | 9 |
|
23 | | -// Configuration for client-side bundle suitable for running in browsers |
24 | | -var clientBundleOutputDir = './wwwroot/dist'; |
25 | | -var clientBundleConfig = merge(sharedConfig(), { |
26 | | - entry: { 'main-client': './ClientApp/boot-client.tsx' }, |
27 | | - module: { |
28 | | - loaders: [ |
29 | | - { test: /\.css$/, loader: ExtractTextPlugin.extract(['css-loader']) }, |
30 | | - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } } |
31 | | - ] |
32 | | - }, |
33 | | - output: { path: path.join(__dirname, clientBundleOutputDir) }, |
34 | | - plugins: [ |
35 | | - new ExtractTextPlugin('site.css'), |
36 | | - new webpack.DllReferencePlugin({ |
37 | | - context: __dirname, |
38 | | - manifest: require('./wwwroot/dist/vendor-manifest.json') |
39 | | - }) |
40 | | - ].concat(isDevBuild ? [ |
41 | | - // Plugins that apply in development builds only |
42 | | - new webpack.SourceMapDevToolPlugin({ |
43 | | - filename: '[file].map', // Remove this line if you prefer inline source maps |
44 | | - moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk |
45 | | - }) |
46 | | - ] : [ |
47 | | - // Plugins that apply in production builds only |
48 | | - new webpack.optimize.OccurenceOrderPlugin(), |
49 | | - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) |
50 | | - ]) |
51 | | -}); |
| 10 | + // Configuration in common to both client-side and server-side bundles |
| 11 | + const sharedConfig = () => ({ |
| 12 | + stats: { modules: false }, |
| 13 | + resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] }, |
| 14 | + output: { |
| 15 | + filename: '[name].js', |
| 16 | + publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix |
| 17 | + }, |
| 18 | + module: { |
| 19 | + rules: [ |
| 20 | + { test: /\.tsx?$/, include: /ClientApp/, use: 'babel-loader' }, |
| 21 | + { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' } |
| 22 | + ] |
| 23 | + }, |
| 24 | + plugins: [new CheckerPlugin()] |
| 25 | + }); |
52 | 26 |
|
53 | | -// Configuration for server-side (prerendering) bundle suitable for running in Node |
54 | | -var serverBundleConfig = merge(sharedConfig(), { |
55 | | - resolve: { packageMains: ['main'] }, |
56 | | - entry: { 'main-server': './ClientApp/boot-server.tsx' }, |
57 | | - plugins: [ |
58 | | - new webpack.DllReferencePlugin({ |
59 | | - context: __dirname, |
60 | | - manifest: require('./ClientApp/dist/vendor-manifest.json'), |
61 | | - sourceType: 'commonjs2', |
62 | | - name: './vendor' |
63 | | - }) |
64 | | - ], |
65 | | - output: { |
66 | | - libraryTarget: 'commonjs', |
67 | | - path: path.join(__dirname, './ClientApp/dist') |
68 | | - }, |
69 | | - target: 'node', |
70 | | - devtool: 'inline-source-map' |
71 | | -}); |
| 27 | + // Configuration for client-side bundle suitable for running in browsers |
| 28 | + const clientBundleOutputDir = './wwwroot/dist'; |
| 29 | + const clientBundleConfig = merge(sharedConfig(), { |
| 30 | + entry: { 'main-client': './ClientApp/boot-client.tsx' }, |
| 31 | + module: { |
| 32 | + rules: [ |
| 33 | + { test: /\.css$/, use: ExtractTextPlugin.extract({ loader: 'css-loader' }) }, |
| 34 | + { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' } |
| 35 | + ] |
| 36 | + }, |
| 37 | + output: { path: path.join(__dirname, clientBundleOutputDir) }, |
| 38 | + plugins: [ |
| 39 | + new ExtractTextPlugin('site.css'), |
| 40 | + new webpack.DllReferencePlugin({ |
| 41 | + context: __dirname, |
| 42 | + manifest: require('./wwwroot/dist/vendor-manifest.json') |
| 43 | + }) |
| 44 | + ].concat(isDevBuild ? [ |
| 45 | + // Plugins that apply in development builds only |
| 46 | + new webpack.SourceMapDevToolPlugin({ |
| 47 | + filename: '[file].map', // Remove this line if you prefer inline source maps |
| 48 | + moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk |
| 49 | + }) |
| 50 | + ] : [ |
| 51 | + // Plugins that apply in production builds only |
| 52 | + new webpack.optimize.UglifyJsPlugin() |
| 53 | + ]) |
| 54 | + }); |
72 | 55 |
|
73 | | -module.exports = [clientBundleConfig, serverBundleConfig]; |
| 56 | + // Configuration for server-side (prerendering) bundle suitable for running in Node |
| 57 | + const serverBundleConfig = merge(sharedConfig(), { |
| 58 | + resolve: { mainFields: ['main'] }, |
| 59 | + entry: { 'main-server': './ClientApp/boot-server.tsx' }, |
| 60 | + plugins: [ |
| 61 | + new webpack.DllReferencePlugin({ |
| 62 | + context: __dirname, |
| 63 | + manifest: require('./ClientApp/dist/vendor-manifest.json'), |
| 64 | + sourceType: 'commonjs2', |
| 65 | + name: './vendor' |
| 66 | + }) |
| 67 | + ], |
| 68 | + output: { |
| 69 | + libraryTarget: 'commonjs', |
| 70 | + path: path.join(__dirname, './ClientApp/dist') |
| 71 | + }, |
| 72 | + target: 'node', |
| 73 | + devtool: 'inline-source-map' |
| 74 | + }); |
| 75 | + |
| 76 | + return [clientBundleConfig, serverBundleConfig]; |
| 77 | +}; |
0 commit comments