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
| 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 webpack = require('webpack');
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' }, 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: [ 'cache-loader', 'logger-loader', 'style-loader', 'css-loader' ] }, { test: /\.less$/, use: [ 'style-loader', 'css-loader', 'less-loader' ] } ] } ] }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html' }), 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, }) ] })
|