blob: 52820ab239f55d5e9c11ec21bf057c9037a8b9ed [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;
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";
suryav972424b377d2025-01-24 15:06:35 +053018 `;
19 } else {
20 return `
21 @import "@/assets/styles/bmc/helpers";
22 @import "@/assets/styles/bootstrap/_helpers";
suryav972424b377d2025-01-24 15:06:35 +053023 `;
24 }
25 })(), // immediately invoked function expression (IIFE)
26 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070027 },
suryav972424b377d2025-01-24 15:06:35 +053028 },
29 devServer: {
Hariharan Rangasamy8e387792025-11-10 12:56:33 +000030 // 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 Muranaka6ce1a072019-12-06 14:13:59 -080034 proxy: {
Derick Montaguefded0d12019-12-11 06:16:40 -060035 '/': {
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080036 target: process.env.BASE_URL,
Derick Montague602e98a2020-10-21 16:20:00 -050037 onProxyRes: (proxyRes) => {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080038 delete proxyRes.headers['strict-transport-security'];
Derick Montague602e98a2020-10-21 16:20:00 -050039 },
40 },
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060041 },
Derick Montague602e98a2020-10-21 16:20:00 -050042 port: 8000,
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060043 },
44 productionSourceMap: false,
Ed Tanousf8207742024-04-08 14:27:07 -070045 chainWebpack: (config) => {
Ed Tanous7d6b44c2024-03-23 14:56:34 -070046 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 Tanousf8207742024-04-08 14:27:07 -070054 config.module
55 .rule('vue')
56 .use('vue-svg-inline-loader')
57 .loader('vue-svg-inline-loader');
Ed Tanous511650a2024-04-20 16:36:00 -070058 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 Tanous1ccd8872024-04-21 17:02:30 -070066 config.plugins.delete('preload');
Ed Tanousb1daec62024-06-06 13:46:21 -070067 if (process.env.NODE_ENV === 'production') {
68 config.plugin('html').tap((options) => {
suryav972424b377d2025-01-24 15:06:35 +053069 options[0].filename = 'index.[hash:8].html';
Ed Tanousb1daec62024-06-06 13:46:21 -070070 return options;
71 });
72 }
Ed Tanousf8207742024-04-08 14:27:07 -070073 },
Derick Montague602e98a2020-10-21 16:20:00 -050074 configureWebpack: (config) => {
Ed Tanous740cbd52024-04-20 16:35:34 -070075 config.plugins.push(
76 new LimitChunkCountPlugin({
77 maxChunks: 1,
78 }),
79 );
80 config.optimization.splitChunks = {
81 cacheGroups: {
82 default: false,
83 },
84 };
Gunnar Mills99706ff2022-01-14 19:52:33 +000085 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 Muranaka9e36f522020-02-05 07:42:34 -080090 const envName = process.env.VUE_APP_ENV_NAME;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070091 const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
92 const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -070093 const hasCustomAppNav =
94 process.env.CUSTOM_APP_NAV === 'true' ? true : false;
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080095
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080096 if (envName !== undefined) {
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070097 if (hasCustomStore) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -070098 // 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 Muranaka044b1bb2020-08-12 14:12:44 -0700102 }
103 if (hasCustomRouter) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700104 // If env has custom router, resolve routes in src/router/index.js
105 config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700106 }
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700107 if (hasCustomAppNav) {
108 // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
Ed Tanous81323992024-02-27 11:26:24 -0800109 config.resolve.alias['./AppNavigationMixin$'] =
110 `@/env/components/AppNavigation/${envName}.js`;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700111 }
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800112 }
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700113
114 if (process.env.NODE_ENV === 'production') {
115 config.plugins.push(
116 new CompressionPlugin({
Derick Montague602e98a2020-10-21 16:20:00 -0500117 deleteOriginalAssets: true,
Ed Tanous81323992024-02-27 11:26:24 -0800118 }),
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700119 );
120 }
Ed Tanous740cbd52024-04-20 16:35:34 -0700121
122 config.performance = {
123 hints: 'warning',
124 maxEntrypointSize: 512000,
125 maxAssetSize: 512000,
126 };
127
128 config.optimization.runtimeChunk = false;
Derick Montaguef3ab8bc2019-12-10 15:13:25 -0600129 },
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -0600130 pluginOptions: {
131 i18n: {
132 localeDir: 'locales',
Derick Montague602e98a2020-10-21 16:20:00 -0500133 enableInSFC: true,
134 },
135 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -0800136};