Last active
December 9, 2019 13:44
-
-
Save jemsgit/da201089f591d225623634efcf2320d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const webpack = require('webpack'); | |
| const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
| const CompressionPlugin = require('compression-webpack-plugin'); | |
| const ManifestPlugin = require('webpack-manifest-plugin'); | |
| const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
| function webpackProductionConfigBuilder(options) { | |
| options = options || {}; | |
| const extractMainCSS = new ExtractTextPlugin(options.extractMainCSS || '[name].[hash].css'); //This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. () | |
| const extractIconsCSS = new ExtractTextPlugin(options.extractIconsCSS || '[name]-icons.[hash].css'); | |
| const extractOptions = Object.assign({ | |
| fallback: require.resolve('style-loader'), | |
| use: [require.resolve('css-loader'), require.resolve('postcss-loader')] | |
| }, options.extractOptions); | |
| return { | |
| module: { | |
| rules: [ | |
| { | |
| test: /\.css$/, | |
| exclude: /icon.*\.css$/, | |
| use: extractMainCSS.extract(extractOptions) | |
| }, | |
| { | |
| test: /icon.*\.css$/, | |
| use: extractIconsCSS.extract(extractOptions) | |
| } | |
| ] | |
| }, | |
| plugins: [ | |
| new webpack.optimize.CommonsChunkPlugin({ | |
| name: 'vendor', | |
| minChunks(module) { | |
| return module.userRequest | |
| && (module.userRequest.indexOf('arui') === -1 || module.userRequest.indexOf('polyfills') !== -1) | |
| && module.userRequest.indexOf('node_modules') !== -1; | |
| } | |
| }), //выделяет общие части нескольких точек входа в отдельную сборку) — заменен на набор API `optimize.splitChunks` | |
| new ManifestPlugin(), //Webpack plugin for generating an asset manifest. holds all the entries and filenames | |
| new webpack.optimize.ModuleConcatenationPlugin(), //enable the common scope concatenation behavior in webpack | |
| new webpack.optimize.UglifyJsPlugin({ | |
| beautify: false, | |
| sourceMap: false, | |
| warnings: false | |
| }), //минификатор | |
| extractMainCSS, | |
| extractIconsCSS, | |
| new OptimizeCssAssetsPlugin(), //search for CSS assets during the Webpack build and will optimize \ minimize the CSS (by default it uses cssnano but a custom CSS processor can be specified) | |
| new CompressionPlugin({ | |
| asset: '[file].gz', | |
| algorithm: 'gzip', | |
| regExp: /\.js$|\.css$|\.png$|\.svg$/, | |
| threshold: 10240, | |
| minRatio: 0.8 | |
| }) //сжимает | |
| ] | |
| }; | |
| } | |
| module.exports = webpackProductionConfigBuilder; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment