blob: 3f3b34c741c9640029439e8bf9e024a7f00774b1 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001const CompressionPlugin = require('compression-webpack-plugin');
Ed Tanous740cbd52024-04-20 16:35:34 -07002const webpack = require('webpack');
3const LimitChunkCountPlugin = webpack.optimize.LimitChunkCountPlugin;
Derick Montaguef3ab8bc2019-12-10 15:13:25 -06004
Yoshie Muranaka74c24f12019-12-03 10:45:46 -08005module.exports = {
suryav972424b377d2025-01-24 15:06:35 +05306 css: {
7 loaderOptions: {
8 sass: {
9 additionalData: (() => {
10 const envName = process.env.VUE_APP_ENV_NAME;
jason westoverd36ac8a2025-11-03 20:58:59 -060011 const hasCustomStyles = process.env.CUSTOM_STYLES === 'true';
suryav972424b377d2025-01-24 15:06:35 +053012 if (hasCustomStyles && envName !== undefined) {
13 return `
14 @import "@/assets/styles/bmc/helpers";
15 @import "@/env/assets/styles/_${envName}";
16 @import "@/assets/styles/bootstrap/_helpers";
suryav972424b377d2025-01-24 15:06:35 +053017 `;
18 } else {
19 return `
20 @import "@/assets/styles/bmc/helpers";
21 @import "@/assets/styles/bootstrap/_helpers";
suryav972424b377d2025-01-24 15:06:35 +053022 `;
23 }
24 })(), // immediately invoked function expression (IIFE)
25 },
jason westoverd36ac8a2025-11-03 20:58:59 -060026 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 Tanous7d6b44c2024-03-23 14:56:34 -070044 },
suryav972424b377d2025-01-24 15:06:35 +053045 },
46 devServer: {
Hariharan Rangasamy8e387792025-11-10 12:56:33 +000047 // 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 Muranaka6ce1a072019-12-06 14:13:59 -080051 proxy: {
Derick Montaguefded0d12019-12-11 06:16:40 -060052 '/': {
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080053 target: process.env.BASE_URL,
Derick Montague602e98a2020-10-21 16:20:00 -050054 onProxyRes: (proxyRes) => {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080055 delete proxyRes.headers['strict-transport-security'];
Derick Montague602e98a2020-10-21 16:20:00 -050056 },
57 },
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060058 },
Derick Montague602e98a2020-10-21 16:20:00 -050059 port: 8000,
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060060 },
61 productionSourceMap: false,
Ed Tanousf8207742024-04-08 14:27:07 -070062 chainWebpack: (config) => {
63 config.module
64 .rule('vue')
65 .use('vue-svg-inline-loader')
66 .loader('vue-svg-inline-loader');
Ed Tanous511650a2024-04-20 16:36:00 -070067 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 Tanous1ccd8872024-04-21 17:02:30 -070075 config.plugins.delete('preload');
Ed Tanousb1daec62024-06-06 13:46:21 -070076 if (process.env.NODE_ENV === 'production') {
77 config.plugin('html').tap((options) => {
suryav972424b377d2025-01-24 15:06:35 +053078 options[0].filename = 'index.[hash:8].html';
Ed Tanousb1daec62024-06-06 13:46:21 -070079 return options;
80 });
81 }
Ed Tanousf8207742024-04-08 14:27:07 -070082 },
Derick Montague602e98a2020-10-21 16:20:00 -050083 configureWebpack: (config) => {
Ed Tanous740cbd52024-04-20 16:35:34 -070084 config.plugins.push(
85 new LimitChunkCountPlugin({
86 maxChunks: 1,
87 }),
88 );
89 config.optimization.splitChunks = {
90 cacheGroups: {
91 default: false,
92 },
93 };
Gunnar Mills99706ff2022-01-14 19:52:33 +000094 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 Muranaka9e36f522020-02-05 07:42:34 -080099 const envName = process.env.VUE_APP_ENV_NAME;
jason westoverd36ac8a2025-11-03 20:58:59 -0600100 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 Muranaka9e36f522020-02-05 07:42:34 -0800103
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800104 if (envName !== undefined) {
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700105 if (hasCustomStore) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700106 // 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 Muranaka044b1bb2020-08-12 14:12:44 -0700110 }
111 if (hasCustomRouter) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700112 // If env has custom router, resolve routes in src/router/index.js
113 config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700114 }
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700115 if (hasCustomAppNav) {
116 // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
Ed Tanous81323992024-02-27 11:26:24 -0800117 config.resolve.alias['./AppNavigationMixin$'] =
118 `@/env/components/AppNavigation/${envName}.js`;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700119 }
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800120 }
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700121
122 if (process.env.NODE_ENV === 'production') {
123 config.plugins.push(
124 new CompressionPlugin({
Derick Montague602e98a2020-10-21 16:20:00 -0500125 deleteOriginalAssets: true,
Ed Tanous81323992024-02-27 11:26:24 -0800126 }),
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700127 );
128 }
Ed Tanous740cbd52024-04-20 16:35:34 -0700129
130 config.performance = {
131 hints: 'warning',
132 maxEntrypointSize: 512000,
133 maxAssetSize: 512000,
134 };
135
136 config.optimization.runtimeChunk = false;
jason westoverd36ac8a2025-11-03 20:58:59 -0600137
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 Montaguef3ab8bc2019-12-10 15:13:25 -0600165 },
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -0600166 pluginOptions: {
167 i18n: {
168 localeDir: 'locales',
Derick Montague602e98a2020-10-21 16:20:00 -0500169 enableInSFC: true,
170 },
171 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -0800172};