Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | const path = require('path'); |
| 4 | const merge = require('webpack-merge'); |
| 5 | const webpack = require('webpack'); |
| 6 | const ServerConfig = require('./webpack.server'); |
| 7 | const webpackCommonConfig = require('./webpack.common'); |
| 8 | const {GlobCopyWebpackPlugin, BaseHrefWebpackPlugin} = require('@angular/cli/plugins/webpack'); |
| 9 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 10 | var CompressionPlugin = require('compression-webpack-plugin'); |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 11 | var currentTime = new Date().getTime(); |
| 12 | |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 13 | const params = {}; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 14 | |
| 15 | const webpackProdConfig = { |
| 16 | module: { |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 17 | rules: [ |
| 18 | {test: /\.(eot|svg)$/, loader: "file-loader?name=/scripts/fonts/[name].[hash:20].[ext]"}, |
| 19 | { |
| 20 | test: /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/, |
| 21 | loader: "url-loader?name=/scripts/images/[name].[hash:20].[ext]&limit=10000" |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 22 | } |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 23 | ] |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 24 | }, |
| 25 | output: { |
| 26 | path: path.join(process.cwd(), "dist"), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 27 | filename: "[name]." + currentTime + ".bundle.js", |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 28 | chunkFilename: "[id].chunk.js", |
| 29 | publicPath: "/sdc1" |
| 30 | }, |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 31 | plugins: [ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 32 | new webpack.DefinePlugin({ |
| 33 | __DEBUG__: JSON.stringify(false), |
| 34 | __ENV__: JSON.stringify('prod') |
| 35 | }), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 36 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 37 | new CopyWebpackPlugin([ |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 38 | { |
| 39 | from: './src/index.html', transform: function (content, path) { |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 40 | content = (content + '').replace(/\.bundle.js/g, '.' + currentTime + '.bundle.jsgz'); |
| 41 | |
| 42 | return content; |
| 43 | } |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 44 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 45 | ]), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 46 | new webpack.optimize.UglifyJsPlugin({ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 47 | beautify: false, |
| 48 | mangle: { |
| 49 | screw_ie8: true, |
| 50 | keep_fnames: true |
| 51 | }, |
| 52 | compress: { |
| 53 | warnings: false, |
| 54 | screw_ie8: true |
| 55 | }, |
| 56 | comments: false |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 57 | }), |
| 58 | new webpack.optimize.AggressiveMergingPlugin(),//Merge chunks |
| 59 | new CompressionPlugin({ |
| 60 | asset: "[path]gz", |
| 61 | algorithm: "gzip", |
| 62 | test: /\.js$|\.css$|\.html$/ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 63 | }) |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 64 | ] |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | module.exports = merge(webpackProdConfig, webpackCommonConfig(params)); |