Guest User

Untitled

a guest
Jul 26th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const merge = require('webpack-merge');
  4. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  5. const HtmlWebpackPlugin = require('html-webpack-plugin');
  6. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  7. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  8. const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
  9.  
  10. const isProduction = process.env.NODE_ENV === 'production';
  11.  
  12. const common = {
  13. target: 'web',
  14.  
  15. entry: {
  16. main: path.resolve(__dirname, 'src', 'index.jsx'),
  17. },
  18.  
  19. output: {
  20. path: path.resolve(__dirname, 'dist'),
  21. filename: isProduction ? '[name].[chunkhash].js' : '[name].js',
  22. publicPath: '/',
  23. },
  24.  
  25. module: {
  26. rules: [
  27. {
  28. test: /\.jsx?$/,
  29. exclude: /node_modules(?!\/astralnalog)/,
  30. use: ['babel-loader?cacheDirectory=true'],
  31. },
  32. {
  33. test: /\.s?[ac]ss$/,
  34. use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
  35. },
  36. {
  37. test: /\.(png|svg|jpg|gif)$/,
  38. use: ['file-loader'],
  39. },
  40. {
  41. test: /\.(woff|woff2|eot|ttf|otf)$/,
  42. use: ['file-loader'],
  43. },
  44. {
  45. test: /\.(pdf)$/,
  46. use: ['file-loader?minetype=application/pdf'],
  47. },
  48. ],
  49. },
  50.  
  51. plugins: [
  52. new webpack.DefinePlugin({
  53. 'process.env': {
  54. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  55. },
  56. }),
  57. new HtmlWebpackPlugin({
  58. inject: false,
  59. cache: true,
  60. minify: isProduction,
  61. template: path.join('src', 'index.html'),
  62. title: 'Title',
  63. }),
  64. new MiniCssExtractPlugin({
  65. filename: isProduction ? '[name].[contenthash].css' : '[name].css',
  66. chunkFilename: isProduction ? '[name].[contenthash].chunk.css' : '[name].chunk.css',
  67. }),
  68. ],
  69.  
  70. resolve: {
  71. extensions: ['.js', '.jsx', '.css', '.scss'],
  72. },
  73.  
  74. devServer: {
  75. stats: 'minimal',
  76. historyApiFallback: true,
  77. contentBase: path.resolve(__dirname, 'dist'),
  78. proxy: {
  79. '/api': 'http://localhost:5000',
  80. '/api/hub': {
  81. ws: true,
  82. target: 'ws://localhost:5000/',
  83. },
  84. },
  85. },
  86. };
  87.  
  88. module.exports = isProduction
  89. ? merge(common, {
  90. plugins: [
  91. new webpack.HashedModuleIdsPlugin(),
  92. new FaviconsWebpackPlugin('./src/favicon.svg'),
  93. ],
  94. optimization: {
  95. minimize: true,
  96. occurrenceOrder: true,
  97. runtimeChunk: true,
  98. splitChunks: {
  99. cacheGroups: {
  100. commons: {
  101. test: /[\\/]node_modules[\\/]/,
  102. name: 'vendors',
  103. chunks: 'all',
  104. },
  105. },
  106. },
  107. minimizer: [
  108. new UglifyJsPlugin({
  109. cache: true,
  110. parallel: true,
  111. uglifyOptions: {
  112. compress: {
  113. drop_console: true,
  114. },
  115. dead_code: true,
  116. },
  117. }),
  118. new OptimizeCSSAssetsPlugin({
  119. cssProcessorOptions: {
  120. discardUnused: { fontFace: false },
  121. discardComments: { removeAll: true },
  122. },
  123. }),
  124. ],
  125. },
  126. })
  127. : merge(common, {
  128. devtool: 'cheap-module-source-map',
  129. plugins: [new webpack.NamedModulesPlugin()],
  130. });
Add Comment
Please, Sign In to add comment