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'); |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 11 | const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 12 | var currentTime = new Date().getTime(); |
| 13 | |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 14 | const params = {}; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 15 | |
| 16 | const webpackProdConfig = { |
| 17 | module: { |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 18 | rules: [ |
| 19 | {test: /\.(eot|svg)$/, loader: "file-loader?name=/scripts/fonts/[name].[hash:20].[ext]"}, |
| 20 | { |
| 21 | test: /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/, |
| 22 | loader: "url-loader?name=/scripts/images/[name].[hash:20].[ext]&limit=10000" |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 23 | } |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 24 | ] |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 25 | }, |
| 26 | output: { |
| 27 | path: path.join(process.cwd(), "dist"), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 28 | filename: "[name]." + currentTime + ".bundle.js", |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 29 | chunkFilename: "[id].chunk.js", |
| 30 | publicPath: "/sdc1" |
| 31 | }, |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 32 | plugins: [ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 33 | new webpack.DefinePlugin({ |
| 34 | __DEBUG__: JSON.stringify(false), |
| 35 | __ENV__: JSON.stringify('prod') |
| 36 | }), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 37 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 38 | new CopyWebpackPlugin([ |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 39 | { |
| 40 | from: './src/index.html', transform: function (content, path) { |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 41 | content = (content + '').replace(/\.bundle.js/g, '.' + currentTime + '.bundle.jsgz'); |
| 42 | |
| 43 | return content; |
| 44 | } |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 45 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 46 | ]), |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 47 | new UglifyJSPlugin({}), |
Michael Lando | 3c3c833 | 2017-07-20 01:29:49 +0300 | [diff] [blame] | 48 | new webpack.optimize.AggressiveMergingPlugin(),//Merge chunks |
| 49 | new CompressionPlugin({ |
| 50 | asset: "[path]gz", |
| 51 | algorithm: "gzip", |
| 52 | test: /\.js$|\.css$|\.html$/ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 53 | }) |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 54 | ] |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | module.exports = merge(webpackProdConfig, webpackCommonConfig(params)); |