blob: 0fc5e6b0f5fa4f4e779b477593adbabc0a09a74e [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";
18 @import '@/assets/styles/_obmc-custom.scss';
19 `;
20 } else {
21 return `
22 @import "@/assets/styles/bmc/helpers";
23 @import "@/assets/styles/bootstrap/_helpers";
24 @import '@/assets/styles/_obmc-custom.scss';
25 `;
26 }
27 })(), // immediately invoked function expression (IIFE)
28 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070029 },
suryav972424b377d2025-01-24 15:06:35 +053030 },
31 devServer: {
32 https: true,
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080033 proxy: {
Derick Montaguefded0d12019-12-11 06:16:40 -060034 '/': {
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080035 target: process.env.BASE_URL,
Derick Montague602e98a2020-10-21 16:20:00 -050036 onProxyRes: (proxyRes) => {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080037 delete proxyRes.headers['strict-transport-security'];
Derick Montague602e98a2020-10-21 16:20:00 -050038 },
39 },
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060040 },
Derick Montague602e98a2020-10-21 16:20:00 -050041 port: 8000,
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060042 },
43 productionSourceMap: false,
Ed Tanousf8207742024-04-08 14:27:07 -070044 chainWebpack: (config) => {
Ed Tanous7d6b44c2024-03-23 14:56:34 -070045 config.resolve.alias.set('vue', '@vue/compat');
46 config.module
47 .rule('vue')
48 .use('vue-loader')
49 .tap((options) => {
50 options['compilerOptions'] = { compatConfig: { MODE: 2 } };
51 return options;
52 });
Ed Tanousf8207742024-04-08 14:27:07 -070053 config.module
54 .rule('vue')
55 .use('vue-svg-inline-loader')
56 .loader('vue-svg-inline-loader');
Ed Tanous511650a2024-04-20 16:36:00 -070057 config.module
58 .rule('ico')
59 .test(/\.ico$/)
60 .use('file-loader')
61 .loader('file-loader')
62 .options({
63 name: '[name].[contenthash:8].[ext]',
64 });
Ed Tanous1ccd8872024-04-21 17:02:30 -070065 config.plugins.delete('preload');
Ed Tanousb1daec62024-06-06 13:46:21 -070066 if (process.env.NODE_ENV === 'production') {
67 config.plugin('html').tap((options) => {
suryav972424b377d2025-01-24 15:06:35 +053068 options[0].filename = 'index.[hash:8].html';
Ed Tanousb1daec62024-06-06 13:46:21 -070069 return options;
70 });
71 }
Ed Tanousf8207742024-04-08 14:27:07 -070072 },
Derick Montague602e98a2020-10-21 16:20:00 -050073 configureWebpack: (config) => {
Ed Tanous740cbd52024-04-20 16:35:34 -070074 config.plugins.push(
75 new LimitChunkCountPlugin({
76 maxChunks: 1,
77 }),
78 );
79 config.optimization.splitChunks = {
80 cacheGroups: {
81 default: false,
82 },
83 };
Gunnar Mills99706ff2022-01-14 19:52:33 +000084 const crypto = require('crypto');
85 const crypto_orig_createHash = crypto.createHash;
86 crypto.createHash = (algorithm) =>
87 crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm);
88
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080089 const envName = process.env.VUE_APP_ENV_NAME;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070090 const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
91 const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -070092 const hasCustomAppNav =
93 process.env.CUSTOM_APP_NAV === 'true' ? true : false;
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080094
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080095 if (envName !== undefined) {
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070096 if (hasCustomStore) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -070097 // If env has custom store, resolve all store modules. Currently found
98 // in src/router/index.js src/store/api.js and src/main.js
99 config.resolve.alias['./store$'] = `@/env/store/${envName}.js`;
100 config.resolve.alias['../store$'] = `@/env/store/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700101 }
102 if (hasCustomRouter) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700103 // If env has custom router, resolve routes in src/router/index.js
104 config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700105 }
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700106 if (hasCustomAppNav) {
107 // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
Ed Tanous81323992024-02-27 11:26:24 -0800108 config.resolve.alias['./AppNavigationMixin$'] =
109 `@/env/components/AppNavigation/${envName}.js`;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700110 }
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800111 }
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700112
113 if (process.env.NODE_ENV === 'production') {
114 config.plugins.push(
115 new CompressionPlugin({
Derick Montague602e98a2020-10-21 16:20:00 -0500116 deleteOriginalAssets: true,
Ed Tanous81323992024-02-27 11:26:24 -0800117 }),
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700118 );
119 }
Ed Tanous740cbd52024-04-20 16:35:34 -0700120
121 config.performance = {
122 hints: 'warning',
123 maxEntrypointSize: 512000,
124 maxAssetSize: 512000,
125 };
126
127 config.optimization.runtimeChunk = false;
Derick Montaguef3ab8bc2019-12-10 15:13:25 -0600128 },
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -0600129 pluginOptions: {
130 i18n: {
131 localeDir: 'locales',
Derick Montague602e98a2020-10-21 16:20:00 -0500132 enableInSFC: true,
133 },
134 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -0800135};