webpack.config.js (2087B)
1 require('dotenv').config(); 2 3 const path = require('path'); 4 const webpack = require('webpack'); 5 const HtmlWebpackPlugin = require('html-webpack-plugin'); 6 const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') 7 .BundleAnalyzerPlugin; 8 const {CleanWebpackPlugin} = require('clean-webpack-plugin'); 9 const ZopfliPlugin = require('zopfli-webpack-plugin'); 10 const RobotstxtPlugin = require('robotstxt-webpack-plugin'); 11 const SitemapPlugin = require('sitemap-webpack-plugin').default; 12 13 const robotOptions = { 14 policy: [ 15 { 16 userAgent: 'Googlebot', 17 allow: '/', 18 crawlDelay: 2, 19 }, 20 { 21 userAgent: '*', 22 allow: '/', 23 crawlDelay: 2, 24 }, 25 ], 26 sitemap: 'http://ybbond.dev/sitemap.xml', 27 host: 'http://ybbond.dev', 28 }; 29 30 const paths = ['/', '/uses/', '/uses', '/about/', '/about']; 31 32 const config = { 33 entry: path.resolve(__dirname, 'src/index'), 34 module: { 35 rules: [ 36 { 37 test: /\.js$/, 38 include: path.resolve(__dirname, 'src'), 39 loader: 'babel-loader', 40 }, 41 ], 42 }, 43 plugins: [ 44 new HtmlWebpackPlugin({ 45 title: 'Yohanes Bandung', 46 template: 'public/index.html', 47 favicon: 'public/favicon.ico', 48 }), 49 new RobotstxtPlugin({ 50 options: robotOptions, 51 }), 52 new SitemapPlugin('https://ybbond.dev', paths), 53 new CleanWebpackPlugin(), 54 new webpack.DefinePlugin({ 55 'process.env.GITHUB_READ_ONLY_TOKEN': JSON.stringify( 56 process.env.GITHUB_READ_ONLY_TOKEN, 57 ), 58 }), 59 new ZopfliPlugin({ 60 asset: '[path].gz[query]', 61 algorithm: 'zopfli', 62 test: /\.(js|html)$/, 63 threshold: 10240, 64 minRatio: 0.8, 65 }), 66 ], 67 devServer: { 68 contentBase: path.resolve(__dirname, 'build'), 69 historyApiFallback: true, 70 hot: true, 71 port: 3000, 72 }, 73 optimization: { 74 splitChunks: { 75 chunks: 'all', 76 }, 77 }, 78 output: { 79 path: path.resolve(__dirname, 'build'), 80 filename: 'bundle.js', 81 }, 82 }; 83 84 if (process.env.WEBPACK_ANALYZE_WEB === 'true') { 85 config.plugins.push(new BundleAnalyzerPlugin()); 86 } 87 88 module.exports = config;