1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| const path = require('path'); const notifier = require('node-notifier'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); const SpeedMeasureWebpack5Plugin = require('speed-measure-webpack5-plugin'); const HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin'); const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer'); const loadersPath = path.resolve(__dirname, 'loaders') const smw = new SpeedMeasureWebpack5Plugin(); const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); const TerserWebpackPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const PurgecssWebpackPlugin = require('purgecss-webpack-plugin');
const glob = require('glob'); const webpack = require('webpack');
const PATHS = { src: path.resolve(__dirname, 'src') }
module.exports = smw.wrap({ mode: 'development', context: process.cwd(), devtool: "source-map", entry: { main: './src/index.js' }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, optimization: { minimize: true, minimizer: [ new TerserWebpackPlugin() ] }, resolve: { extensions: ['.js', '.jsx', '.json'], alias: { utils: path.join(__dirname, './src/utils/index.js') } }, resolveLoader: { modules: [loadersPath, 'node_modules'] }, externals: { jquery: 'jQuery' }, module: { rules: [ { test: /\.js$/, include: path.resolve(__dirname, 'src'), exclude: /node_modules/, use: [ { loader: 'thread-loader', options: { workers: 3 } }, 'babel-loader' ] }, { oneOf: [ { test: /\.css$/, use: [ MiniCssExtractPlugin.loader, 'css-loader' ] }, { test: /\.less$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'less-loader' ] } ] }, { test: /\.(gif|png|jpe?g|svg)$/i, use: [ 'file-loader', { loader: 'image-webpack-loader', options: { mozjpeg: { progressive: true, }, optipng: { enabled: false, }, pngquant: { quality: [0.65, 0.90], speed: 4 }, gifsicle: { interlaced: false, }, webp: { quality: 75 } } }, ], } ] }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html', minify: { collapseWhitespace: true, removeComments: true } }), new HtmlWebpackExternalsPlugin({ externals: [{ module: 'jquery', entry: 'https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js', global: 'jQuery' }] }), new FriendlyErrorsWebpackPlugin({ onErrors: (severity, errors) => { const error = errors[0]; notifier.notify({ title: severity + ': ' + error.name, message: error.message }) } }), new webpack.IgnorePlugin({ resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/ }), new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true, }), new OptimizeCssAssetsWebpackPlugin(), new MiniCssExtractPlugin({ filename: '[name].css' }), new PurgecssWebpackPlugin({ paths: glob.sync(`${PATHS.src}/**/*`, {nodir: true}) }) ] })
|