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 = { |
| 6 | devServer: { |
Ed Tanous | 9c72979 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 7 | server: { |
| 8 | type: 'https', |
| 9 | }, |
Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 10 | proxy: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 11 | '/': { |
Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 12 | target: process.env.BASE_URL, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 13 | onProxyRes: (proxyRes) => { |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 14 | // This header is ignored in the browser so removing |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 15 | // it so we don't see warnings in the browser console |
| 16 | delete proxyRes.headers['strict-transport-security']; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 17 | }, |
| 18 | }, |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 19 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 20 | port: 8000, |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 21 | }, |
| 22 | productionSourceMap: false, |
Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 23 | chainWebpack: (config) => { |
Ed Tanous | 9c72979 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 24 | config.resolve.alias.set('vue', '@vue/compat'); |
| 25 | config.module |
| 26 | .rule('vue') |
| 27 | .use('vue-loader') |
| 28 | .tap((options) => { |
| 29 | options['compilerOptions'] = { compatConfig: { MODE: 2 } }; |
| 30 | return options; |
| 31 | }); |
Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 32 | config.module |
| 33 | .rule('vue') |
| 34 | .use('vue-svg-inline-loader') |
| 35 | .loader('vue-svg-inline-loader'); |
Ed Tanous | 9c72979 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 36 | |
Ed Tanous | 511650a | 2024-04-20 16:36:00 -0700 | [diff] [blame] | 37 | config.module |
| 38 | .rule('ico') |
| 39 | .test(/\.ico$/) |
| 40 | .use('file-loader') |
| 41 | .loader('file-loader') |
| 42 | .options({ |
| 43 | name: '[name].[contenthash:8].[ext]', |
| 44 | }); |
Ed Tanous | 1ccd887 | 2024-04-21 17:02:30 -0700 | [diff] [blame] | 45 | config.plugins.delete('preload'); |
Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 46 | if (process.env.NODE_ENV === 'production') { |
| 47 | config.plugin('html').tap((options) => { |
Ed Tanous | 01aeaf0 | 2024-07-17 10:42:38 -0700 | [diff] [blame] | 48 | options[0].filename = 'index.[contenthash:8].html'; |
Ed Tanous | b1daec6 | 2024-06-06 13:46:21 -0700 | [diff] [blame] | 49 | return options; |
| 50 | }); |
| 51 | } |
Ed Tanous | f820774 | 2024-04-08 14:27:07 -0700 | [diff] [blame] | 52 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 53 | configureWebpack: (config) => { |
Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 54 | config.plugins.push( |
| 55 | new LimitChunkCountPlugin({ |
| 56 | maxChunks: 1, |
| 57 | }), |
| 58 | ); |
| 59 | config.optimization.splitChunks = { |
| 60 | cacheGroups: { |
| 61 | default: false, |
| 62 | }, |
| 63 | }; |
Ed Tanous | 01aeaf0 | 2024-07-17 10:42:38 -0700 | [diff] [blame] | 64 | if (process.env.NODE_ENV === 'development') { |
| 65 | config.devtool = 'source-map'; |
| 66 | } |
Gunnar Mills | 99706ff | 2022-01-14 19:52:33 +0000 | [diff] [blame] | 67 | const crypto = require('crypto'); |
| 68 | const crypto_orig_createHash = crypto.createHash; |
| 69 | crypto.createHash = (algorithm) => |
| 70 | crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm); |
| 71 | |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 72 | const envName = process.env.VUE_APP_ENV_NAME; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 73 | const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false; |
| 74 | const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false; |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 75 | const hasCustomAppNav = |
| 76 | process.env.CUSTOM_APP_NAV === 'true' ? true : false; |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 77 | |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 78 | if (envName !== undefined) { |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 79 | if (hasCustomStore) { |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 80 | // If env has custom store, resolve all store modules. Currently found |
| 81 | // in src/router/index.js src/store/api.js and src/main.js |
| 82 | config.resolve.alias['./store$'] = `@/env/store/${envName}.js`; |
| 83 | config.resolve.alias['../store$'] = `@/env/store/${envName}.js`; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 84 | } |
| 85 | if (hasCustomRouter) { |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 86 | // If env has custom router, resolve routes in src/router/index.js |
| 87 | config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`; |
Yoshie Muranaka | 044b1bb | 2020-08-12 14:12:44 -0700 | [diff] [blame] | 88 | } |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 89 | if (hasCustomAppNav) { |
| 90 | // 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] | 91 | config.resolve.alias['./AppNavigationMixin$'] = |
| 92 | `@/env/components/AppNavigation/${envName}.js`; |
Yoshie Muranaka | 0214fed | 2020-09-03 13:25:50 -0700 | [diff] [blame] | 93 | } |
Yoshie Muranaka | 9e36f52 | 2020-02-05 07:42:34 -0800 | [diff] [blame] | 94 | } |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 95 | |
| 96 | if (process.env.NODE_ENV === 'production') { |
| 97 | config.plugins.push( |
| 98 | new CompressionPlugin({ |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 99 | deleteOriginalAssets: true, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 100 | }), |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 101 | ); |
| 102 | } |
Ed Tanous | 740cbd5 | 2024-04-20 16:35:34 -0700 | [diff] [blame] | 103 | |
| 104 | config.performance = { |
| 105 | hints: 'warning', |
| 106 | maxEntrypointSize: 512000, |
| 107 | maxAssetSize: 512000, |
| 108 | }; |
| 109 | |
| 110 | config.optimization.runtimeChunk = false; |
Derick Montague | f3ab8bc | 2019-12-10 15:13:25 -0600 | [diff] [blame] | 111 | }, |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 112 | pluginOptions: { |
| 113 | i18n: { |
| 114 | localeDir: 'locales', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 115 | enableInSFC: true, |
| 116 | }, |
| 117 | }, |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 118 | }; |