Advertisement
KVAnton

Untitled

Jan 22nd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const {CleanWebpackPlugin} = require('clean-webpack-plugin');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4.  
  5. conf = {
  6.     entry: {
  7.         site: './src/js/index.js',
  8.     },
  9.     output: {
  10.         filename: './js/[name].js',
  11.         path: path.resolve(__dirname, 'dist'),
  12.     },
  13.     module: {
  14.         rules: [
  15.             {
  16.                 test: /^[^\_+]*\.js$/,
  17.                 include: path.resolve(__dirname, 'src/js'),
  18.                 exclude: path.resolve(__dirname, 'node_modules'),
  19.                 use: {
  20.                     loader: 'babel-loader',
  21.                     options: {
  22.                         presets: ['@babel/preset-env'],
  23.                     },
  24.                 },
  25.             },
  26.             {
  27.                 test: /src[\\/]js[\\/]\_+.*\.js$/,
  28.                 include: path.resolve(__dirname, 'src/js'),
  29.                 exclude: path.resolve(__dirname, 'node_modules'),
  30.                 use: {
  31.                     loader: 'raw-loader',
  32.                 },
  33.             },
  34.         ],
  35.     },
  36.     optimization: {
  37.         minimize: true,
  38.         minimizer: [
  39.             new TerserPlugin({
  40.                 include: /\.min.*\.js$/,
  41.                 cache: true,
  42.                 parallel: 4,
  43.                 sourceMap: true,
  44.                 terserOptions: {
  45.                     // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
  46.                     ie8: false,
  47.                     safari10: false,
  48.                     output: {
  49.                         beautify: false,
  50.                         comments: false,
  51.                     },
  52.                 },
  53.             }),
  54.         ],
  55.     },
  56.     plugins: [new CleanWebpackPlugin()],
  57. };
  58.  
  59. module.exports = (env, options) => {
  60.     let production = options.mode === 'production';
  61.     conf.devtool = production ? false : 'eval-sourcemap';
  62.     if (production) {
  63.         conf.optimization.splitChunks = {
  64.             chunks: 'all',
  65.             // minSize: 100000,
  66.             maxSize: 244000,
  67.             maxInitialRequests: Infinity,
  68.             cacheGroups: {
  69.                 vendor: {
  70.                     test: /[\\/]node_modules[\\/]/,
  71.                     enforce: true,
  72.                     reuseExistingChunk: true,
  73.                     name(module) {
  74.                         const packageName = module.context.match(
  75.                             /[\\/]node_modules[\\/](.*?)([\\/]|$)/
  76.                         )[1];
  77.                         return packageName.replace('@', '');
  78.                     },
  79.                 },
  80.                 nobandle: {
  81.                     test: /[\\/]src[\\/]js[\\/]\_+.*$/,
  82.                     enforce: true,
  83.                     reuseExistingChunk: true,
  84.                     name(module) {
  85.                         const packageName = module.rawRequest.match(
  86.                             /\.[\\/](.*?)(\.|$)/
  87.                         )[1];
  88.                         return packageName.replace('@', '');
  89.                     },
  90.                 },
  91.             },
  92.         };
  93.     }
  94.     return conf;
  95. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement