Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | const CompressionPlugin = require('compression-webpack-plugin'); |
Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 2 | const webpack = require('webpack'); |
| 3 | const LimitChunkCountPlugin = webpack.optimize.LimitChunkCountPlugin; |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 4 | |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 5 | module.exports = { |
Yoshie Muranaka | d388a28 | 2020-07-08 16:15:46 -0700 | [diff] [blame] | 6 | css: { |
| 7 | loaderOptions: { |
| 8 | sass: { |
| 9 | prependData: () => { |
| 10 | const envName = process.env.VUE_APP_ENV_NAME; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 11 | const hasCustomStyles = |
| 12 | process.env.CUSTOM_STYLES === 'true' ? true : false; |
| 13 | if (hasCustomStyles && envName !== undefined) { |
Yoshie Muranaka | d388a28 | 2020-07-08 16:15:46 -0700 | [diff] [blame] | 14 | // 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 Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 21 | @import "@/env/assets/styles/_${envName}"; |
Yoshie Muranaka | d388a28 | 2020-07-08 16:15:46 -0700 | [diff] [blame] | 22 | @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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 37 | }, |
| 38 | }, |
| 39 | }, |
Yoshie Muranaka | d388a28 | 2020-07-08 16:15:46 -0700 | [diff] [blame] | 40 | }, |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 41 | devServer: { |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 42 | https: true, |
Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 43 | proxy: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 44 | '/': { |
Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 45 | target: process.env.BASE_URL, |
Dixsie Wolmers | bf37b31 | 2021-10-12 15:07:41 -0500 | [diff] [blame] | 46 | headers: { |
| 47 | Connection: 'keep-alive', |
| 48 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 49 | onProxyRes: (proxyRes) => { |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 50 | // This header is ignored in the browser so removing |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 51 | // it so we don't see warnings in the browser console |
| 52 | delete proxyRes.headers['strict-transport-security']; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 53 | }, |
| 54 | }, |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 55 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | port: 8000, |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 57 | }, |
| 58 | productionSourceMap: false, |
Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 59 | chainWebpack: (config) => { |
| 60 | config.module |
| 61 | .rule('vue') |
| 62 | .use('vue-svg-inline-loader') |
| 63 | .loader('vue-svg-inline-loader'); |
Ed Tanous | 511650a | 2024-04-20 16:36:00 -0700 | [diff] [blame] | 64 | 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 Tanous | 1ccd887 | 2024-04-21 17:02:30 -0700 | [diff] [blame] | 72 | config.plugins.delete('preload'); |
| 73 | config.plugin('html').tap((options) => { |
| 74 | options[0].filename = 'index.[hash:8].html'; |
| 75 | return options; |
| 76 | }); |
Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 77 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 78 | configureWebpack: (config) => { |
Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 79 | config.plugins.push( |
| 80 | new LimitChunkCountPlugin({ |
| 81 | maxChunks: 1, |
| 82 | }), |
| 83 | ); |
| 84 | config.optimization.splitChunks = { |
| 85 | cacheGroups: { |
| 86 | default: false, |
| 87 | }, |
| 88 | }; |
Gunnar Mills | 99706ff | 2022-01-14 19:52:33 +0000 | [diff] [blame] | 89 | 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 Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 94 | const envName = process.env.VUE_APP_ENV_NAME; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 95 | const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false; |
| 96 | const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false; |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 97 | const hasCustomAppNav = |
| 98 | process.env.CUSTOM_APP_NAV === 'true' ? true : false; |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 99 | |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 100 | if (envName !== undefined) { |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 101 | if (hasCustomStore) { |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 102 | // 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 Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 106 | } |
| 107 | if (hasCustomRouter) { |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 108 | // If env has custom router, resolve routes in src/router/index.js |
| 109 | config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 110 | } |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 111 | if (hasCustomAppNav) { |
| 112 | // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 113 | config.resolve.alias['./AppNavigationMixin$'] = |
| 114 | `@/env/components/AppNavigation/${envName}.js`; |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 115 | } |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 116 | } |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 117 | |
| 118 | if (process.env.NODE_ENV === 'production') { |
| 119 | config.plugins.push( |
| 120 | new CompressionPlugin({ |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 121 | deleteOriginalAssets: true, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 122 | }), |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 123 | ); |
| 124 | } |
Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 125 | |
| 126 | config.performance = { |
| 127 | hints: 'warning', |
| 128 | maxEntrypointSize: 512000, |
| 129 | maxAssetSize: 512000, |
| 130 | }; |
| 131 | |
| 132 | config.optimization.runtimeChunk = false; |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 133 | }, |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 134 | pluginOptions: { |
| 135 | i18n: { |
| 136 | localeDir: 'locales', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 137 | enableInSFC: true, |
| 138 | }, |
| 139 | }, |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 140 | }; |