| 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; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 11 | const hasCustomStyles = process.env.CUSTOM_STYLES === 'true'; |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 12 | if (hasCustomStyles && envName !== undefined) { |
| 13 | return ` |
| 14 | @import "@/assets/styles/bmc/helpers"; |
| 15 | @import "@/env/assets/styles/_${envName}"; |
| 16 | @import "@/assets/styles/bootstrap/_helpers"; |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 17 | `; |
| 18 | } else { |
| 19 | return ` |
| 20 | @import "@/assets/styles/bmc/helpers"; |
| 21 | @import "@/assets/styles/bootstrap/_helpers"; |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 22 | `; |
| 23 | } |
| 24 | })(), // immediately invoked function expression (IIFE) |
| 25 | }, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 26 | scss: { |
| 27 | additionalData: (() => { |
| 28 | const envName = process.env.VUE_APP_ENV_NAME; |
| 29 | const hasCustomStyles = process.env.CUSTOM_STYLES === 'true'; |
| 30 | if (hasCustomStyles && envName !== undefined) { |
| 31 | return ` |
| 32 | @import "@/assets/styles/bmc/helpers"; |
| 33 | @import "@/env/assets/styles/_${envName}"; |
| 34 | @import "@/assets/styles/bootstrap/_helpers"; |
| 35 | `; |
| 36 | } else { |
| 37 | return ` |
| 38 | @import "@/assets/styles/bmc/helpers"; |
| 39 | @import "@/assets/styles/bootstrap/_helpers"; |
| 40 | `; |
| 41 | } |
| 42 | })(), |
| 43 | }, |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 44 | }, |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 45 | }, |
| 46 | devServer: { |
| Hariharan Rangasamy | 8e38779 | 2025-11-10 12:56:33 +0000 | [diff] [blame] | 47 | // Set DEV_HTTPS=true to run with HTTPS (helpful for testing secure-only features or with a signed cert) |
| 48 | // ref https://webpack.js.org/configuration/dev-server/#devserverserver |
| 49 | server: |
| 50 | process.env.DEV_HTTPS === 'true' ? { type: 'https' } : { type: 'http' }, |
| Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 51 | proxy: { |
| Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 52 | '/': { |
| Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 53 | target: process.env.BASE_URL, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 54 | onProxyRes: (proxyRes) => { |
| Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 55 | delete proxyRes.headers['strict-transport-security']; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | }, |
| 57 | }, |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 58 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 59 | port: 8000, |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 60 | }, |
| 61 | productionSourceMap: false, |
| Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 62 | chainWebpack: (config) => { |
| 63 | config.module |
| 64 | .rule('vue') |
| 65 | .use('vue-svg-inline-loader') |
| 66 | .loader('vue-svg-inline-loader'); |
| Ed Tanous | 511650a | 2024-04-20 16:36:00 -0700 | [diff] [blame] | 67 | config.module |
| 68 | .rule('ico') |
| 69 | .test(/\.ico$/) |
| 70 | .use('file-loader') |
| 71 | .loader('file-loader') |
| 72 | .options({ |
| 73 | name: '[name].[contenthash:8].[ext]', |
| 74 | }); |
| Ed Tanous | 1ccd887 | 2024-04-21 17:02:30 -0700 | [diff] [blame] | 75 | config.plugins.delete('preload'); |
| Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 76 | if (process.env.NODE_ENV === 'production') { |
| 77 | config.plugin('html').tap((options) => { |
| suryav9724 | 24b377d | 2025-01-24 15:06:35 +0530 | [diff] [blame] | 78 | options[0].filename = 'index.[hash:8].html'; |
| Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 79 | return options; |
| 80 | }); |
| 81 | } |
| Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 82 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 83 | configureWebpack: (config) => { |
| Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 84 | config.plugins.push( |
| 85 | new LimitChunkCountPlugin({ |
| 86 | maxChunks: 1, |
| 87 | }), |
| 88 | ); |
| 89 | config.optimization.splitChunks = { |
| 90 | cacheGroups: { |
| 91 | default: false, |
| 92 | }, |
| 93 | }; |
| Gunnar Mills | 99706ff | 2022-01-14 19:52:33 +0000 | [diff] [blame] | 94 | const crypto = require('crypto'); |
| 95 | const crypto_orig_createHash = crypto.createHash; |
| 96 | crypto.createHash = (algorithm) => |
| 97 | crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm); |
| 98 | |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 99 | const envName = process.env.VUE_APP_ENV_NAME; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 100 | const hasCustomStore = process.env.CUSTOM_STORE === 'true'; |
| 101 | const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true'; |
| 102 | const hasCustomAppNav = process.env.CUSTOM_APP_NAV === 'true'; |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 103 | |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 104 | if (envName !== undefined) { |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 105 | if (hasCustomStore) { |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 106 | // If env has custom store, resolve all store modules. Currently found |
| 107 | // in src/router/index.js src/store/api.js and src/main.js |
| 108 | config.resolve.alias['./store$'] = `@/env/store/${envName}.js`; |
| 109 | config.resolve.alias['../store$'] = `@/env/store/${envName}.js`; |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 110 | } |
| 111 | if (hasCustomRouter) { |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 112 | // If env has custom router, resolve routes in src/router/index.js |
| 113 | config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`; |
| Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 114 | } |
| Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 115 | if (hasCustomAppNav) { |
| 116 | // 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] | 117 | config.resolve.alias['./AppNavigationMixin$'] = |
| 118 | `@/env/components/AppNavigation/${envName}.js`; |
| Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 119 | } |
| Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 120 | } |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 121 | |
| 122 | if (process.env.NODE_ENV === 'production') { |
| 123 | config.plugins.push( |
| 124 | new CompressionPlugin({ |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | deleteOriginalAssets: true, |
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 126 | }), |
| Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 127 | ); |
| 128 | } |
| Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 129 | |
| 130 | config.performance = { |
| 131 | hints: 'warning', |
| 132 | maxEntrypointSize: 512000, |
| 133 | maxAssetSize: 512000, |
| 134 | }; |
| 135 | |
| 136 | config.optimization.runtimeChunk = false; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 137 | |
| 138 | // Define Vue 3 compile-time feature flags |
| 139 | // These flags must be explicitly defined to avoid Vue warnings and optimize bundle size |
| 140 | config.plugins.push( |
| 141 | new webpack.DefinePlugin({ |
| 142 | // Enable Options API support (required - this codebase uses Options API extensively) |
| 143 | // Setting to true includes Options API in the bundle (~3kb gzipped) |
| 144 | // Cannot be disabled until full migration to Composition API |
| 145 | __VUE_OPTIONS_API__: JSON.stringify(true), |
| 146 | |
| 147 | // Disable Vue Devtools in production builds for security and performance |
| 148 | // Devtools automatically enabled in development mode regardless of this flag |
| 149 | __VUE_PROD_DEVTOOLS__: JSON.stringify(false), |
| 150 | |
| 151 | // Disable detailed hydration mismatch warnings in production |
| 152 | // This is a SPA (not SSR), so hydration warnings don't apply |
| 153 | // Reduces bundle size and eliminates unnecessary runtime checks |
| 154 | __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false), |
| 155 | |
| 156 | // Expose session storage toggle to client code |
| 157 | 'process.env.STORE_SESSION': JSON.stringify( |
| 158 | process.env.STORE_SESSION || '', |
| 159 | ), |
| 160 | 'process.env.VUE_APP_STORE_SESSION': JSON.stringify( |
| 161 | process.env.VUE_APP_STORE_SESSION || '', |
| 162 | ), |
| 163 | }), |
| 164 | ); |
| Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 165 | }, |
| Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 166 | pluginOptions: { |
| 167 | i18n: { |
| 168 | localeDir: 'locales', |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 169 | enableInSFC: true, |
| 170 | }, |
| 171 | }, |
| Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 172 | }; |