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