blob: 01d48b9458c331d57076ff74e0d5a49446c3c828 [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 = {
Yoshie Muranakad388a282020-07-08 16:15:46 -07006 css: {
7 loaderOptions: {
8 sass: {
9 prependData: () => {
10 const envName = process.env.VUE_APP_ENV_NAME;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070011 const hasCustomStyles =
12 process.env.CUSTOM_STYLES === 'true' ? true : false;
13 if (hasCustomStyles && envName !== undefined) {
Yoshie Muranakad388a282020-07-08 16:15:46 -070014 // If there is an env name defined, import Sass
15 // overrides.
16 // It is important that these imports stay in this
17 // order to make sure enviroment overrides
18 // take precedence over the default BMC styles
19 return `
20 @import "@/assets/styles/bmc/helpers";
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070021 @import "@/env/assets/styles/_${envName}";
Yoshie Muranakad388a282020-07-08 16:15:46 -070022 @import "@/assets/styles/bootstrap/_helpers";
23 `;
24 } else {
25 // Include helper imports so single file components
26 // do not need to include helper imports
27
28 // BMC Helpers must be imported before Bootstrap helpers to
29 // take advantage of Bootstrap's use of the Sass !default
30 // statement. Moving this helper after results in Bootstrap
31 // variables taking precedence over BMC's
32 return `
33 @import "@/assets/styles/bmc/helpers";
34 @import "@/assets/styles/bootstrap/_helpers";
35 `;
36 }
Derick Montague602e98a2020-10-21 16:20:00 -050037 },
38 },
39 },
Yoshie Muranakad388a282020-07-08 16:15:46 -070040 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -080041 devServer: {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080042 https: true,
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080043 proxy: {
Derick Montaguefded0d12019-12-11 06:16:40 -060044 '/': {
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -080045 target: process.env.BASE_URL,
Dixsie Wolmersbf37b312021-10-12 15:07:41 -050046 headers: {
47 Connection: 'keep-alive',
48 },
Derick Montague602e98a2020-10-21 16:20:00 -050049 onProxyRes: (proxyRes) => {
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -060050 // This header is ignored in the browser so removing
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080051 // it so we don't see warnings in the browser console
52 delete proxyRes.headers['strict-transport-security'];
Derick Montague602e98a2020-10-21 16:20:00 -050053 },
54 },
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060055 },
Derick Montague602e98a2020-10-21 16:20:00 -050056 port: 8000,
Derick Montaguef3ab8bc2019-12-10 15:13:25 -060057 },
58 productionSourceMap: false,
Ed Tanousf8207742024-04-08 14:27:07 -070059 chainWebpack: (config) => {
60 config.module
61 .rule('vue')
62 .use('vue-svg-inline-loader')
63 .loader('vue-svg-inline-loader');
Ed Tanous511650a2024-04-20 16:36:00 -070064 config.module
65 .rule('ico')
66 .test(/\.ico$/)
67 .use('file-loader')
68 .loader('file-loader')
69 .options({
70 name: '[name].[contenthash:8].[ext]',
71 });
Ed Tanous1ccd8872024-04-21 17:02:30 -070072 config.plugins.delete('preload');
73 config.plugin('html').tap((options) => {
74 options[0].filename = 'index.[hash:8].html';
75 return options;
76 });
Ed Tanousf8207742024-04-08 14:27:07 -070077 },
Derick Montague602e98a2020-10-21 16:20:00 -050078 configureWebpack: (config) => {
Ed Tanous740cbd52024-04-20 16:35:34 -070079 config.plugins.push(
80 new LimitChunkCountPlugin({
81 maxChunks: 1,
82 }),
83 );
84 config.optimization.splitChunks = {
85 cacheGroups: {
86 default: false,
87 },
88 };
Gunnar Mills99706ff2022-01-14 19:52:33 +000089 const crypto = require('crypto');
90 const crypto_orig_createHash = crypto.createHash;
91 crypto.createHash = (algorithm) =>
92 crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm);
93
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080094 const envName = process.env.VUE_APP_ENV_NAME;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -070095 const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
96 const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -070097 const hasCustomAppNav =
98 process.env.CUSTOM_APP_NAV === 'true' ? true : false;
Yoshie Muranaka9e36f522020-02-05 07:42:34 -080099
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800100 if (envName !== undefined) {
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700101 if (hasCustomStore) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700102 // If env has custom store, resolve all store modules. Currently found
103 // in src/router/index.js src/store/api.js and src/main.js
104 config.resolve.alias['./store$'] = `@/env/store/${envName}.js`;
105 config.resolve.alias['../store$'] = `@/env/store/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700106 }
107 if (hasCustomRouter) {
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700108 // If env has custom router, resolve routes in src/router/index.js
109 config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
Yoshie Muranaka044b1bb2020-08-12 14:12:44 -0700110 }
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700111 if (hasCustomAppNav) {
112 // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
Ed Tanous81323992024-02-27 11:26:24 -0800113 config.resolve.alias['./AppNavigationMixin$'] =
114 `@/env/components/AppNavigation/${envName}.js`;
Yoshie Muranaka0214fed2020-09-03 13:25:50 -0700115 }
Yoshie Muranaka9e36f522020-02-05 07:42:34 -0800116 }
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700117
118 if (process.env.NODE_ENV === 'production') {
119 config.plugins.push(
120 new CompressionPlugin({
Derick Montague602e98a2020-10-21 16:20:00 -0500121 deleteOriginalAssets: true,
Ed Tanous81323992024-02-27 11:26:24 -0800122 }),
Yoshie Muranaka816d9472020-09-03 11:19:28 -0700123 );
124 }
Ed Tanous740cbd52024-04-20 16:35:34 -0700125
126 config.performance = {
127 hints: 'warning',
128 maxEntrypointSize: 512000,
129 maxAssetSize: 512000,
130 };
131
132 config.optimization.runtimeChunk = false;
Derick Montaguef3ab8bc2019-12-10 15:13:25 -0600133 },
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -0600134 pluginOptions: {
135 i18n: {
136 localeDir: 'locales',
Derick Montague602e98a2020-10-21 16:20:00 -0500137 enableInSFC: true,
138 },
139 },
Yoshie Muranaka74c24f12019-12-03 10:45:46 -0800140};