|
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'); |
6 |
| -var extractCSS = new ExtractTextPlugin('vendor.css'); |
| 1 | +const path = require('path'); |
| 2 | +const webpack = require('webpack'); |
| 3 | +const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 4 | +const merge = require('webpack-merge'); |
7 | 5 |
|
8 |
| -var sharedConfig = { |
9 |
| - resolve: { extensions: [ '', '.js' ] }, |
10 |
| - module: { |
11 |
| - loaders: [ |
12 |
| - { test: /\.json$/, loader: require.resolve('json-loader') }, |
13 |
| - { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, loader: 'url-loader?limit=100000' } |
| 6 | +module.exports = (env) => { |
| 7 | + const extractCSS = new ExtractTextPlugin('vendor.css'); |
| 8 | + const isDevBuild = !(env && env.prod); |
| 9 | + const sharedConfig = { |
| 10 | + stats: { modules: false }, |
| 11 | + resolve: { extensions: [ '.js' ] }, |
| 12 | + module: { |
| 13 | + rules: [ |
| 14 | + { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' } |
| 15 | + ] |
| 16 | + }, |
| 17 | + entry: { |
| 18 | + vendor: [ |
| 19 | + '@angular/common', |
| 20 | + '@angular/compiler', |
| 21 | + '@angular/core', |
| 22 | + '@angular/http', |
| 23 | + '@angular/platform-browser', |
| 24 | + '@angular/platform-browser-dynamic', |
| 25 | + '@angular/router', |
| 26 | + '@angular/platform-server', |
| 27 | + 'angular2-universal', |
| 28 | + 'angular2-universal-polyfills', |
| 29 | + 'bootstrap', |
| 30 | + 'bootstrap/dist/css/bootstrap.css', |
| 31 | + 'es6-shim', |
| 32 | + 'es6-promise', |
| 33 | + 'event-source-polyfill', |
| 34 | + 'jquery', |
| 35 | + 'zone.js', |
| 36 | + ] |
| 37 | + }, |
| 38 | + output: { |
| 39 | + publicPath: '/dist/', |
| 40 | + filename: '[name].js', |
| 41 | + library: '[name]_[hash]' |
| 42 | + }, |
| 43 | + plugins: [ |
| 44 | + new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable) |
| 45 | + new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580 |
| 46 | + new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100 |
14 | 47 | ]
|
15 |
| - }, |
16 |
| - entry: { |
17 |
| - vendor: [ |
18 |
| - '@angular/common', |
19 |
| - '@angular/compiler', |
20 |
| - '@angular/core', |
21 |
| - '@angular/http', |
22 |
| - '@angular/platform-browser', |
23 |
| - '@angular/platform-browser-dynamic', |
24 |
| - '@angular/router', |
25 |
| - '@angular/platform-server', |
26 |
| - 'angular2-universal', |
27 |
| - 'angular2-universal-polyfills', |
28 |
| - 'bootstrap', |
29 |
| - 'bootstrap/dist/css/bootstrap.css', |
30 |
| - 'es6-shim', |
31 |
| - 'es6-promise', |
32 |
| - 'event-source-polyfill', |
33 |
| - 'jquery', |
34 |
| - 'zone.js', |
35 |
| - ] |
36 |
| - }, |
37 |
| - output: { |
38 |
| - publicPath: '/dist/', |
39 |
| - filename: '[name].js', |
40 |
| - library: '[name]_[hash]' |
41 |
| - }, |
42 |
| - plugins: [ |
43 |
| - new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable) |
44 |
| - new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580 |
45 |
| - new webpack.IgnorePlugin(/^vertx$/), // Workaround for https://github.com/stefanpenner/es6-promise/issues/100 |
46 |
| - new webpack.NormalModuleReplacementPlugin(/\/iconv-loader$/, require.resolve('node-noop')), // Workaround for https://github.com/andris9/encoding/issues/16 |
47 |
| - ] |
48 |
| -}; |
| 48 | + }; |
49 | 49 |
|
50 |
| -var clientBundleConfig = merge(sharedConfig, { |
51 |
| - output: { path: path.join(__dirname, 'wwwroot', 'dist') }, |
52 |
| - module: { |
53 |
| - loaders: [ |
54 |
| - { test: /\.css(\?|$)/, loader: extractCSS.extract(['css-loader']) } |
55 |
| - ] |
56 |
| - }, |
57 |
| - plugins: [ |
58 |
| - extractCSS, |
59 |
| - new webpack.DllPlugin({ |
60 |
| - path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), |
61 |
| - name: '[name]_[hash]' |
62 |
| - }) |
63 |
| - ].concat(isDevBuild ? [] : [ |
64 |
| - new webpack.optimize.OccurenceOrderPlugin(), |
65 |
| - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) |
66 |
| - ]) |
67 |
| -}); |
| 50 | + const clientBundleConfig = merge(sharedConfig, { |
| 51 | + output: { path: path.join(__dirname, 'wwwroot', 'dist') }, |
| 52 | + module: { |
| 53 | + rules: [ |
| 54 | + { test: /\.css(\?|$)/, use: extractCSS.extract({ loader: 'css-loader' }) } |
| 55 | + ] |
| 56 | + }, |
| 57 | + plugins: [ |
| 58 | + extractCSS, |
| 59 | + new webpack.DllPlugin({ |
| 60 | + path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), |
| 61 | + name: '[name]_[hash]' |
| 62 | + }) |
| 63 | + ].concat(isDevBuild ? [] : [ |
| 64 | + new webpack.optimize.UglifyJsPlugin() |
| 65 | + ]) |
| 66 | + }); |
68 | 67 |
|
69 |
| -var serverBundleConfig = merge(sharedConfig, { |
70 |
| - target: 'node', |
71 |
| - resolve: { packageMains: ['main'] }, |
72 |
| - output: { |
73 |
| - path: path.join(__dirname, 'ClientApp', 'dist'), |
74 |
| - libraryTarget: 'commonjs2', |
75 |
| - }, |
76 |
| - module: { |
77 |
| - loaders: [ { test: /\.css(\?|$)/, loader: 'to-string-loader!css-loader' } ] |
78 |
| - }, |
79 |
| - entry: { vendor: ['aspnet-prerendering'] }, |
80 |
| - plugins: [ |
81 |
| - new webpack.DllPlugin({ |
82 |
| - path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), |
83 |
| - name: '[name]_[hash]' |
84 |
| - }) |
85 |
| - ] |
86 |
| -}); |
| 68 | + const serverBundleConfig = merge(sharedConfig, { |
| 69 | + target: 'node', |
| 70 | + resolve: { mainFields: ['main'] }, |
| 71 | + output: { |
| 72 | + path: path.join(__dirname, 'ClientApp', 'dist'), |
| 73 | + libraryTarget: 'commonjs2', |
| 74 | + }, |
| 75 | + module: { |
| 76 | + rules: [ { test: /\.css(\?|$)/, use: ['to-string-loader', 'css-loader'] } ] |
| 77 | + }, |
| 78 | + entry: { vendor: ['aspnet-prerendering'] }, |
| 79 | + plugins: [ |
| 80 | + new webpack.DllPlugin({ |
| 81 | + path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'), |
| 82 | + name: '[name]_[hash]' |
| 83 | + }) |
| 84 | + ] |
| 85 | + }); |
87 | 86 |
|
88 |
| -module.exports = [clientBundleConfig, serverBundleConfig]; |
| 87 | + return [clientBundleConfig, serverBundleConfig]; |
| 88 | +} |
0 commit comments