|
1 | | -const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'), |
| 1 | +const glob = require('glob'), |
| 2 | + path = require('path'), |
| 3 | + UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'), |
| 4 | + HtmlWebpackPlugin = require('html-webpack-plugin'), |
2 | 5 | CompressionPlugin = require('compression-webpack-plugin'), |
3 | | - webpackConfig = require("./webpack.config.base"), |
4 | | - helpers = require("./helpers"), |
| 6 | + ExtractTextPlugin = require('extract-text-webpack-plugin'), |
| 7 | + PurifyCSSPlugin = require('purifycss-webpack'), |
| 8 | + FaviconsWebpackPlugin = require('favicons-webpack-plugin'), |
| 9 | + autoprefixer = require('autoprefixer'), |
| 10 | + webpackConfig = require('./webpack.config.base'), |
| 11 | + helpers = require('./helpers'), |
5 | 12 | DefinePlugin = require('webpack/lib/DefinePlugin'), |
6 | 13 | env = require('../environment/prod.env'); |
7 | 14 |
|
8 | | -webpackConfig.entry["main.min"] = helpers.root("/src/main.ts"); |
| 15 | +const extractSass = new ExtractTextPlugin({ |
| 16 | + filename: 'css/[name].[contenthash].css', |
| 17 | + disable: process.env.NODE_ENV === 'development' |
| 18 | +}); |
| 19 | + |
| 20 | +const purifyCss = new PurifyCSSPlugin({ |
| 21 | + paths: glob.sync(path.join(__dirname, '../src/**/*.html')), |
| 22 | + purifyOptions: { |
| 23 | + info: true, |
| 24 | + whitelist: [] |
| 25 | + } |
| 26 | +}); |
| 27 | + |
| 28 | +webpackConfig.module.rules = [...webpackConfig.module.rules, |
| 29 | + { |
| 30 | + test: /\.scss$/, |
| 31 | + use: extractSass.extract({ |
| 32 | + use: [{ |
| 33 | + loader: 'css-loader', |
| 34 | + options: { |
| 35 | + minimize: true, |
| 36 | + sourceMap: true, |
| 37 | + importLoaders: 2 |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + loader: 'postcss-loader', |
| 42 | + options: { |
| 43 | + plugins: () => [autoprefixer] |
| 44 | + } |
| 45 | + }, |
| 46 | + { |
| 47 | + loader: 'sass-loader', |
| 48 | + options: { |
| 49 | + outputStyle: 'expanded', |
| 50 | + sourceMap: true, |
| 51 | + sourceMapContents: true |
| 52 | + } |
| 53 | + } |
| 54 | + ], |
| 55 | + // use style-loader in development |
| 56 | + fallback: 'style-loader' |
| 57 | + }) |
| 58 | + }, |
| 59 | + { |
| 60 | + test: /\.(jpg|png|gif)$/, |
| 61 | + loader: 'file-loader?name=assets/img/[name].[ext]' |
| 62 | + }, |
| 63 | + { |
| 64 | + test: /\.(eot|svg|ttf|woff|woff2)$/, |
| 65 | + loader: 'file-loader?name=fonts/[name].[ext]' |
| 66 | + } |
| 67 | +]; |
| 68 | + |
| 69 | +// ensure ts lint fails the build |
| 70 | +webpackConfig.module.rules[0].options = { |
| 71 | + failOnHint: true |
| 72 | +}; |
9 | 73 |
|
10 | 74 | webpackConfig.plugins = [...webpackConfig.plugins, |
| 75 | + extractSass, |
| 76 | + purifyCss, |
| 77 | + new HtmlWebpackPlugin({ |
| 78 | + inject: true, |
| 79 | + template: helpers.root('/src/index.html'), |
| 80 | + favicon: helpers.root('/src/favicon.ico'), |
| 81 | + minify: { |
| 82 | + removeComments: true, |
| 83 | + collapseWhitespace: true, |
| 84 | + removeRedundantAttributes: true, |
| 85 | + useShortDoctype: true, |
| 86 | + removeEmptyAttributes: true, |
| 87 | + removeStyleLinkTypeAttributes: true, |
| 88 | + keepClosingSlash: true, |
| 89 | + minifyJS: true, |
| 90 | + minifyCSS: true, |
| 91 | + minifyURLs: true |
| 92 | + } |
| 93 | + }), |
11 | 94 | new UglifyJsPlugin({ |
12 | 95 | include: /\.min\.js$/, |
13 | 96 | minimize: true |
14 | 97 | }), |
15 | 98 | new CompressionPlugin({ |
16 | | - asset: "[path].gz[query]", |
| 99 | + asset: '[path].gz[query]', |
17 | 100 | test: /\.min\.js$/ |
18 | 101 | }), |
19 | 102 | new DefinePlugin({ |
20 | 103 | 'process.env': env |
21 | | - }) |
| 104 | + }), |
| 105 | + new FaviconsWebpackPlugin(helpers.root('/src/icon.png')) |
22 | 106 | ]; |
23 | 107 |
|
24 | 108 | module.exports = webpackConfig; |
0 commit comments