xref: /openbmc/webui-vue/vue.config.js (revision de23ea23d88451a2fa2774ec72053772603c23ae)
1const CompressionPlugin = require('compression-webpack-plugin');
2const webpack = require('webpack');
3const LimitChunkCountPlugin = webpack.optimize.LimitChunkCountPlugin;
4
5module.exports = {
6  devServer: {
7    server: {
8      type: 'https',
9    },
10    proxy: {
11      '/': {
12        target: process.env.BASE_URL,
13        onProxyRes: (proxyRes) => {
14          // This header is ignored in the browser so removing
15          // it so we don't see warnings in the browser console
16          delete proxyRes.headers['strict-transport-security'];
17        },
18      },
19    },
20    port: 8000,
21  },
22  productionSourceMap: false,
23  chainWebpack: (config) => {
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      });
32    config.module
33      .rule('vue')
34      .use('vue-svg-inline-loader')
35      .loader('vue-svg-inline-loader');
36
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      });
45    config.plugins.delete('preload');
46    if (process.env.NODE_ENV === 'production') {
47      config.plugin('html').tap((options) => {
48        options[0].filename = 'index.[hash:8].html';
49        return options;
50      });
51    }
52  },
53  configureWebpack: (config) => {
54    config.plugins.push(
55      new LimitChunkCountPlugin({
56        maxChunks: 1,
57      }),
58    );
59    config.optimization.splitChunks = {
60      cacheGroups: {
61        default: false,
62      },
63    };
64    config.devtool = 'source-map';
65    const crypto = require('crypto');
66    const crypto_orig_createHash = crypto.createHash;
67    crypto.createHash = (algorithm) =>
68      crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm);
69
70    const envName = process.env.VUE_APP_ENV_NAME;
71    const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
72    const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
73    const hasCustomAppNav =
74      process.env.CUSTOM_APP_NAV === 'true' ? true : false;
75
76    if (envName !== undefined) {
77      if (hasCustomStore) {
78        // If env has custom store, resolve all store modules. Currently found
79        // in src/router/index.js src/store/api.js and src/main.js
80        config.resolve.alias['./store$'] = `@/env/store/${envName}.js`;
81        config.resolve.alias['../store$'] = `@/env/store/${envName}.js`;
82      }
83      if (hasCustomRouter) {
84        // If env has custom router, resolve routes in src/router/index.js
85        config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
86      }
87      if (hasCustomAppNav) {
88        // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
89        config.resolve.alias['./AppNavigationMixin$'] =
90          `@/env/components/AppNavigation/${envName}.js`;
91      }
92    }
93
94    if (process.env.NODE_ENV === 'production') {
95      config.plugins.push(
96        new CompressionPlugin({
97          deleteOriginalAssets: true,
98        }),
99      );
100    }
101
102    config.performance = {
103      hints: 'warning',
104      maxEntrypointSize: 512000,
105      maxAssetSize: 512000,
106    };
107
108    config.optimization.runtimeChunk = false;
109  },
110  pluginOptions: {
111    i18n: {
112      localeDir: 'locales',
113      enableInSFC: true,
114    },
115  },
116};
117