Advertisement
Guest User

webapck

a guest
Apr 7th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. require('@babel/polyfill');
  4. const webpack = require('webpack');
  5. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  6. const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');
  7. const Dotenv = require('dotenv-webpack');
  8. const TerserPlugin = require('terser-webpack-plugin');
  9. const CompressionPlugin = require('compression-webpack-plugin');
  10. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  11. const PurgecssPlugin = require('purgecss-webpack-plugin');
  12. const glob = require('glob');
  13. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  14. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  15.  
  16. module.exports = {
  17.   entry: ['@babel/polyfill', './src/index.js'],
  18.   output: {
  19.     path: path.resolve('dist'),
  20.     filename: '[name].[contenthash].js',
  21.     chunkFilename: '[name].[contenthash].js',
  22.     publicPath: '/',
  23.   },
  24.   mode: process.env.NODE_ENV || 'development',
  25.   resolve: {
  26.     modules: [path.resolve(__dirname, 'src'), 'node_modules'],
  27.     extensions: ['.js', '.jsx'],
  28.   },
  29.   devServer: {
  30.     historyApiFallback: true,
  31.     port: 7099,
  32.   },
  33.   module: {
  34.     rules: [
  35.       {
  36.         // this is so that we can compile any React,
  37.         // ES6 and above into normal ES5 syntax
  38.         test: /\.(js|jsx)$/,
  39.         // we do not want anything from node_modules to be compiled
  40.         exclude: /node_modules/,
  41.         use: ['babel-loader'],
  42.       },
  43.       {
  44.         test: /\.(css|scss)$/,
  45.         use: [
  46.           'style-loader', // creates style nodes from JS strings
  47.           'css-loader', // translates CSS into CommonJS
  48.           'sass-loader', // compiles Sass to CSS, using Node Sass by default
  49.         ],
  50.       },
  51.       {
  52.         test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
  53.         loaders: ['file-loader'],
  54.       },
  55.     ],
  56.   },
  57.   // optimization: {
  58.   //   minimizer: [
  59.   //     new TerserPlugin({
  60.   //       cache: true,
  61.   //       parallel: true,
  62.   //       // extractComments: 'all',
  63.   //       terserOptions: {
  64.   //         output: {
  65.   //           comments: false,
  66.   //         },
  67.   //       },
  68.   //     }),
  69.   //     new UglifyJsPlugin(),
  70.   //     new OptimizeCSSAssetsPlugin({}),
  71.   //   ],
  72.   //   runtimeChunk: 'single',
  73.   //   splitChunks: {
  74.   //     chunks: 'all',
  75.   //     maxInitialRequests: Infinity,
  76.   //     minSize: 0,
  77.   //     cacheGroups: {
  78.   //       vendor: {
  79.   //         test: /[\\/]node_modules[\\/]/,
  80.   //         name(module) {
  81.   //           const packageName = module.context.match(
  82.   //             /[\\/]node_modules[\\/](.*?)([\\/]|$)/,
  83.   //           )[1];
  84.   //           return `n.${packageName.replace('@', '')}`;
  85.   //         },
  86.   //       },
  87.   //     },
  88.   //   },
  89.   // },
  90.   optimization: {
  91.     splitChunks: {
  92.       cacheGroups: {
  93.         commons: {
  94.           test: /[\\/]node_modules[\\/]/,
  95.           name: 'vendor',
  96.           chunks: 'all',
  97.         },
  98.       },
  99.     },
  100.   },
  101.   plugins: [
  102.     new HtmlWebpackPlugin({
  103.       template: path.join(__dirname, 'public', 'index.html'),
  104.     }),
  105.     new MiniCssExtractPlugin(),
  106.     new PurgecssPlugin({
  107.       paths: glob.sync(`${path.join(__dirname, 'src')}/**/*`, { nodir: true }),
  108.     }),
  109.     new Dotenv({
  110.       path: './.env', // Path to .env file (this is the default)
  111.     }),
  112.     new webpack.DefinePlugin({
  113.       'process.env.API_DOMAIN': JSON.stringify(process.env.API_DOMAIN),
  114.       'process.env.API_HOSTNAME': JSON.stringify(process.env.API_HOSTNAME),
  115.       'process.env.API_DOMAIN_DASHBOARD': JSON.stringify(
  116.         process.env.API_DOMAIN_DASHBOARD,
  117.       ),
  118.       'process.env.API_DOMAIN_REGISTER': JSON.stringify(
  119.         process.env.API_DOMAIN_REGISTER,
  120.       ),
  121.       'process.env.URL_CHAT': JSON.stringify(process.env.URL_CHAT),
  122.     }),
  123.     // new CleanWebpackPlugin(),
  124.     // new DynamicCdnWebpackPlugin(),
  125.     // new webpack.HashedModuleIdsPlugin(),
  126.     // new CompressionPlugin({
  127.     //   cache: true,
  128.     // }),
  129.   ],
  130. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement