Advertisement
Guest User

Untitled

a guest
Mar 25th, 2021
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Build config for electron renderer process
  3.  */
  4.  
  5. import path from 'path';
  6. import webpack from 'webpack';
  7. import MiniCssExtractPlugin from 'mini-css-extract-plugin';
  8. import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
  9. import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
  10. import { merge } from 'webpack-merge';
  11. import TerserPlugin from 'terser-webpack-plugin';
  12. import baseConfig from './webpack.config.base';
  13. import CheckNodeEnv from '../scripts/CheckNodeEnv';
  14. import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
  15.  
  16. CheckNodeEnv('production');
  17. DeleteSourceMaps();
  18.  
  19. const devtoolsConfig = process.env.DEBUG_PROD === 'true' ? {
  20.   devtool: 'source-map'
  21. } : {};
  22.  
  23. export default merge(baseConfig, {
  24.   ...devtoolsConfig,
  25.  
  26.   mode: 'production',
  27.  
  28.   target: 'electron-renderer',
  29.  
  30.   entry: [
  31.     'core-js',
  32.     'regenerator-runtime/runtime',
  33.     path.join(__dirname, '../../src/index.tsx'),
  34.   ],
  35.  
  36.   output: {
  37.     path: path.join(__dirname, '../../src/dist'),
  38.     publicPath: './dist/',
  39.     filename: 'renderer.prod.js',
  40.   },
  41.  
  42.   module: {
  43.     rules: [
  44.       {
  45.         test: /.s?css$/,
  46.         use: [
  47.           {
  48.             loader: MiniCssExtractPlugin.loader,
  49.             options: {
  50.               // `./dist` can't be inerhited for publicPath for styles. Otherwise generated paths will be ./dist/dist
  51.               publicPath: './',
  52.             },
  53.           },
  54.           'css-loader',
  55.           'sass-loader',
  56.           {
  57.             loader: 'postcss-loader',
  58.             options: {
  59.               postcssOptions: {
  60.                 plugins: [require('tailwindcss'), require('autoprefixer')],
  61.               },
  62.             }
  63.           }
  64.         ],
  65.       },
  66.       // WOFF Font
  67.       {
  68.         test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
  69.         use: {
  70.           loader: 'url-loader',
  71.           options: {
  72.             limit: 10000,
  73.             mimetype: 'application/font-woff',
  74.           },
  75.         },
  76.       },
  77.       // WOFF2 Font
  78.       {
  79.         test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
  80.         use: {
  81.           loader: 'url-loader',
  82.           options: {
  83.             limit: 10000,
  84.             mimetype: 'application/font-woff',
  85.           },
  86.         },
  87.       },
  88.       // OTF Font
  89.       {
  90.         test: /\.otf(\?v=\d+\.\d+\.\d+)?$/,
  91.         use: {
  92.           loader: 'url-loader',
  93.           options: {
  94.             limit: 10000,
  95.             mimetype: 'font/otf',
  96.           },
  97.         },
  98.       },
  99.       // TTF Font
  100.       {
  101.         test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
  102.         use: {
  103.           loader: 'url-loader',
  104.           options: {
  105.             limit: 10000,
  106.             mimetype: 'application/octet-stream',
  107.           },
  108.         },
  109.       },
  110.       // EOT Font
  111.       {
  112.         test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
  113.         use: 'file-loader',
  114.       },
  115.       // SVG Font
  116.       {
  117.         test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  118.         use: {
  119.           loader: 'url-loader',
  120.           options: {
  121.             limit: 10000,
  122.             mimetype: 'image/svg+xml',
  123.           },
  124.         },
  125.       },
  126.       // Common Image Formats
  127.       {
  128.         test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
  129.         use: 'url-loader',
  130.       },
  131.     ],
  132.   },
  133.  
  134.   optimization: {
  135.     minimize: true,
  136.     minimizer:
  137.       [
  138.         new TerserPlugin({
  139.           parallel: true,
  140.         }),
  141.         new CssMinimizerPlugin(),
  142.       ],
  143.   },
  144.  
  145.   plugins: [
  146.     /**
  147.      * Create global constants which can be configured at compile time.
  148.      *
  149.      * Useful for allowing different behaviour between development builds and
  150.      * release builds
  151.      *
  152.      * NODE_ENV should be production so that modules do not perform certain
  153.      * development checks
  154.      */
  155.     new webpack.EnvironmentPlugin({
  156.       NODE_ENV: 'production',
  157.       DEBUG_PROD: false,
  158.     }),
  159.  
  160.     new MiniCssExtractPlugin({
  161.       filename: 'style.css',
  162.     }),
  163.  
  164.     new BundleAnalyzerPlugin({
  165.       analyzerMode:
  166.         process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
  167.       openAnalyzer: process.env.OPEN_ANALYZER === 'true',
  168.     }),
  169.   ],
  170. });
  171.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement