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