|
| 1 | +const autoprefixer = require('autoprefixer'); |
| 2 | +const merge = require('webpack-merge'); |
| 3 | +const path = require('path'); |
| 4 | +const webpack = require('webpack'); |
| 5 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| 6 | +const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); |
| 7 | +const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin'); |
| 8 | + |
| 9 | +const common = require('./webpack.common'); |
| 10 | + |
| 11 | +module.exports = merge(common, { |
| 12 | + mode: 'production', |
| 13 | + devtool: 'source-map', |
| 14 | + module: { |
| 15 | + rules: [ |
| 16 | + { |
| 17 | + test: /\.html$/, |
| 18 | + use: { |
| 19 | + loader: 'html-loader', |
| 20 | + options: { |
| 21 | + minimize: true |
| 22 | + } |
| 23 | + } |
| 24 | + }, |
| 25 | + { |
| 26 | + test: /\.css$/, |
| 27 | + use: [ |
| 28 | + MiniCssExtractPlugin.loader, |
| 29 | + { |
| 30 | + loader: 'css-loader', |
| 31 | + options: { importLoaders: 1 } |
| 32 | + }, |
| 33 | + { |
| 34 | + loader: 'postcss-loader', |
| 35 | + options: { |
| 36 | + plugins: () => [autoprefixer()] |
| 37 | + } |
| 38 | + } |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + test: /\.(gif|jpg|png|svg|ico)$/, |
| 43 | + include: path.resolve(__dirname, 'statik/images'), |
| 44 | + use: [ |
| 45 | + { |
| 46 | + loader: 'file-loader', |
| 47 | + options: { |
| 48 | + name: '[name].[ext]', |
| 49 | + useRelativePath: true |
| 50 | + } |
| 51 | + }, |
| 52 | + 'image-webpack-loader' |
| 53 | + ] |
| 54 | + } |
| 55 | + ] |
| 56 | + }, |
| 57 | + optimization: { |
| 58 | + splitChunks: { |
| 59 | + chunks: 'all', |
| 60 | + name: true |
| 61 | + }, |
| 62 | + minimizer: [ |
| 63 | + new OptimizeCSSAssetsPlugin({ |
| 64 | + cssProcessorOptions: { discardUnused: false } |
| 65 | + }) |
| 66 | + ] |
| 67 | + }, |
| 68 | + plugins: [ |
| 69 | + new MiniCssExtractPlugin({ |
| 70 | + filename: '[name].bundle.css', |
| 71 | + chunkFilename: '[id].css' |
| 72 | + }), |
| 73 | + new UglifyJsWebpackPlugin({ |
| 74 | + sourceMap: true |
| 75 | + }), |
| 76 | + new webpack.DefinePlugin({ |
| 77 | + 'process.env.NODE_ENV': JSON.stringify('production') |
| 78 | + }) |
| 79 | + ] |
| 80 | +}); |
0 commit comments