blob: 2fab59fa09b09121bb68adb6ef1751a9587e949f [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: {
30 https: true,
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080031 proxy: {
Derick Montaguefded0d12019-12-11 06:16:40 -060032 '/': {
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080033 target: process.env.BASE_URL,
Derick Montague602e98a2020-10-21 16:20:00 -050034 onProxyRes: (proxyRes) => {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080035 delete proxyRes.headers['strict-transport-security'];
Derick Montague602e98a2020-10-21 16:20:00 -050036 },
37 },
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060038 },
Derick Montague602e98a2020-10-21 16:20:00 -050039 port: 8000,
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060040 },
41 productionSourceMap: false,
Ed Tanousf8207742024-04-08 14:27:07 -070042 chainWebpack: (config) => {
Ed Tanous7d6b44c2024-03-23 14:56:34 -070043 config.resolve.alias.set('vue', '@vue/compat');
44 config.module
45 .rule('vue')
46 .use('vue-loader')
47 .tap((options) => {
48 options['compilerOptions'] = { compatConfig: { MODE: 2 } };
49 return options;
50 });
Ed Tanousf8207742024-04-08 14:27:07 -070051 config.module
52 .rule('vue')
53 .use('vue-svg-inline-loader')
54 .loader('vue-svg-inline-loader');
Ed Tanous511650a2024-04-20 16:36:00 -070055 config.module
56 .rule('ico')
57 .test(/\.ico$/)
58 .use('file-loader')
59 .loader('file-loader')
60 .options({
61 name: '[name].[contenthash:8].[ext]',
62 });
Ed Tanous1ccd8872024-04-21 17:02:30 -070063 config.plugins.delete('preload');
Ed Tanousb1daec62024-06-06 13:46:21 -070064 if (process.env.NODE_ENV === 'production') {
65 config.plugin('html').tap((options) => {
suryav972424b377d2025-01-24 15:06:35 +053066 options[0].filename = 'index.[hash:8].html';
Ed Tanousb1daec62024-06-06 13:46:21 -070067 return options;
68 });
69 }
Ed Tanousf8207742024-04-08 14:27:07 -070070 },
Derick Montague602e98a2020-10-21 16:20:00 -050071 configureWebpack: (config) => {
Ed Tanous740cbd52024-04-20 16:35:34 -070072 config.plugins.push(
73 new LimitChunkCountPlugin({
74 maxChunks: 1,
75 }),
76 );
77 config.optimization.splitChunks = {
78 cacheGroups: {
79 default: false,
80 },
81 };
Gunnar Mills99706ff2022-01-14 19:52:33 +000082 const crypto = require('crypto');
83 const crypto_orig_createHash = crypto.createHash;
84 crypto.createHash = (algorithm) =>
85 crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm);
86
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080087 const envName = process.env.VUE_APP_ENV_NAME;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070088 const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
89 const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -070090 const hasCustomAppNav =
91 process.env.CUSTOM_APP_NAV === 'true' ? true : false;
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080092
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080093 if (envName !== undefined) {
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070094 if (hasCustomStore) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -070095 // If env has custom store, resolve all store modules. Currently found
96 // in src/router/index.js src/store/api.js and src/main.js
97 config.resolve.alias['./store$'] = `@/env/store/${envName}.js`;
98 config.resolve.alias['../store$'] = `@/env/store/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070099 }
100 if (hasCustomRouter) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700101 // If env has custom router, resolve routes in src/router/index.js
102 config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700103 }
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700104 if (hasCustomAppNav) {
105 // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
Ed Tanous81323992024-02-27 11:26:24 -0800106 config.resolve.alias['./AppNavigationMixin$'] =
107 `@/env/components/AppNavigation/${envName}.js`;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700108 }
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800109 }
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700110
111 if (process.env.NODE_ENV === 'production') {
112 config.plugins.push(
113 new CompressionPlugin({
Derick Montague602e98a2020-10-21 16:20:00 -0500114 deleteOriginalAssets: true,
Ed Tanous81323992024-02-27 11:26:24 -0800115 }),
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700116 );
117 }
Ed Tanous740cbd52024-04-20 16:35:34 -0700118
119 config.performance = {
120 hints: 'warning',
121 maxEntrypointSize: 512000,
122 maxAssetSize: 512000,
123 };
124
125 config.optimization.runtimeChunk = false;
Derick Montaguef3ab8bc2019-12-10 15:13:25 -0600126 },
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -0600127 pluginOptions: {
128 i18n: {
129 localeDir: 'locales',
Derick Montague602e98a2020-10-21 16:20:00 -0500130 enableInSFC: true,
131 },
132 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -0800133};