| Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | const CompressionPlugin = require('compression-webpack-plugin'); |
| Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 2 | const webpack = require('webpack'); |
| 3 | const LimitChunkCountPlugin = webpack.optimize.LimitChunkCountPlugin; |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 4 | |
| Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 5 | module.exports = { |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 6 | css: { |
| 7 | loaderOptions: { |
| 8 | sass: { |
| 9 | additionalData: (() => { |
| 10 | const envName = process.env.VUE_APP_ENV_NAME; |
| 11 | const hasCustomStyles = |
| 12 | process.env.CUSTOM_STYLES === 'true' ? true : false; |
| 13 | if (hasCustomStyles && envName !== undefined) { |
| 14 | return ` |
| 15 | @import "@/assets/styles/bmc/helpers"; |
| 16 | @import "@/env/assets/styles/_${envName}"; |
| 17 | @import "@/assets/styles/bootstrap/_helpers"; |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 18 | `; |
| 19 | } else { |
| 20 | return ` |
| 21 | @import "@/assets/styles/bmc/helpers"; |
| 22 | @import "@/assets/styles/bootstrap/_helpers"; |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 23 | `; |
| 24 | } |
| 25 | })(), // immediately invoked function expression (IIFE) |
| 26 | }, |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 27 | }, |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 28 | }, |
| 29 | devServer: { |
| Hariharan Rangasamy | 8e38779 | 2025-11-10 12:56:33 +0000 | [diff] [blame^] | 30 | // Set DEV_HTTPS=true to run with HTTPS (helpful for testing secure-only features or with a signed cert) |
| 31 | // ref https://webpack.js.org/configuration/dev-server/#devserverserver |
| 32 | server: |
| 33 | process.env.DEV_HTTPS === 'true' ? { type: 'https' } : { type: 'http' }, |
| Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 34 | proxy: { |
| Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 35 | '/': { |
| Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 36 | target: process.env.BASE_URL, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 37 | onProxyRes: (proxyRes) => { |
| Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 38 | delete proxyRes.headers['strict-transport-security']; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 39 | }, |
| 40 | }, |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 41 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 42 | port: 8000, |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 43 | }, |
| 44 | productionSourceMap: false, |
| Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 45 | chainWebpack: (config) => { |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 46 | config.resolve.alias.set('vue', '@vue/compat'); |
| 47 | config.module |
| 48 | .rule('vue') |
| 49 | .use('vue-loader') |
| 50 | .tap((options) => { |
| 51 | options['compilerOptions'] = { compatConfig: { MODE: 2 } }; |
| 52 | return options; |
| 53 | }); |
| Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 54 | config.module |
| 55 | .rule('vue') |
| 56 | .use('vue-svg-inline-loader') |
| 57 | .loader('vue-svg-inline-loader'); |
| Ed Tanous | 511650a | 2024-04-20 16:36:00 -0700 | [diff] [blame] | 58 | config.module |
| 59 | .rule('ico') |
| 60 | .test(/\.ico$/) |
| 61 | .use('file-loader') |
| 62 | .loader('file-loader') |
| 63 | .options({ |
| 64 | name: '[name].[contenthash:8].[ext]', |
| 65 | }); |
| Ed Tanous | 1ccd887 | 2024-04-21 17:02:30 -0700 | [diff] [blame] | 66 | config.plugins.delete('preload'); |
| Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 67 | if (process.env.NODE_ENV === 'production') { |
| 68 | config.plugin('html').tap((options) => { |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 69 | options[0].filename = 'index.[hash:8].html'; |
| Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 70 | return options; |
| 71 | }); |
| 72 | } |
| Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 73 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 74 | configureWebpack: (config) => { |
| Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 75 | config.plugins.push( |
| 76 | new LimitChunkCountPlugin({ |
| 77 | maxChunks: 1, |
| 78 | }), |
| 79 | ); |
| 80 | config.optimization.splitChunks = { |
| 81 | cacheGroups: { |
| 82 | default: false, |
| 83 | }, |
| 84 | }; |
| Gunnar Mills | 99706ff | 2022-01-14 19:52:33 +0000 | [diff] [blame] | 85 | const crypto = require('crypto'); |
| 86 | const crypto_orig_createHash = crypto.createHash; |
| 87 | crypto.createHash = (algorithm) => |
| 88 | crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm); |
| 89 | |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 90 | const envName = process.env.VUE_APP_ENV_NAME; |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 91 | const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false; |
| 92 | const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false; |
| Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 93 | const hasCustomAppNav = |
| 94 | process.env.CUSTOM_APP_NAV === 'true' ? true : false; |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 95 | |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 96 | if (envName !== undefined) { |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 97 | if (hasCustomStore) { |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 98 | // If env has custom store, resolve all store modules. Currently found |
| 99 | // in src/router/index.js src/store/api.js and src/main.js |
| 100 | config.resolve.alias['./store$'] = `@/env/store/${envName}.js`; |
| 101 | config.resolve.alias['../store$'] = `@/env/store/${envName}.js`; |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 102 | } |
| 103 | if (hasCustomRouter) { |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 104 | // If env has custom router, resolve routes in src/router/index.js |
| 105 | config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`; |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 106 | } |
| Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 107 | if (hasCustomAppNav) { |
| 108 | // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue |
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 109 | config.resolve.alias['./AppNavigationMixin$'] = |
| 110 | `@/env/components/AppNavigation/${envName}.js`; |
| Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 111 | } |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 112 | } |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 113 | |
| 114 | if (process.env.NODE_ENV === 'production') { |
| 115 | config.plugins.push( |
| 116 | new CompressionPlugin({ |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 117 | deleteOriginalAssets: true, |
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 118 | }), |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 119 | ); |
| 120 | } |
| Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 121 | |
| 122 | config.performance = { |
| 123 | hints: 'warning', |
| 124 | maxEntrypointSize: 512000, |
| 125 | maxAssetSize: 512000, |
| 126 | }; |
| 127 | |
| 128 | config.optimization.runtimeChunk = false; |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 129 | }, |
| Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 130 | pluginOptions: { |
| 131 | i18n: { |
| 132 | localeDir: 'locales', |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 133 | enableInSFC: true, |
| 134 | }, |
| 135 | }, |
| Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 136 | }; |