xref: /openbmc/webui-vue/vue.config.js (revision a6c682cb)
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.[contenthash: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    if (process.env.NODE_ENV === 'development') {
65      config.devtool = 'source-map';
66    }
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
72    const envName = process.env.VUE_APP_ENV_NAME;
73    const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
74    const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
75    const hasCustomAppNav =
76      process.env.CUSTOM_APP_NAV === 'true' ? true : false;
77
78    if (envName !== undefined) {
79      if (hasCustomStore) {
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`;
84      }
85      if (hasCustomRouter) {
86        // If env has custom router, resolve routes in src/router/index.js
87        config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
88      }
89      if (hasCustomAppNav) {
90        // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
91        config.resolve.alias['./AppNavigationMixin$'] =
92          `@/env/components/AppNavigation/${envName}.js`;
93      }
94    }
95
96    if (process.env.NODE_ENV === 'production') {
97      config.plugins.push(
98        new CompressionPlugin({
99          deleteOriginalAssets: true,
100        }),
101      );
102    }
103
104    config.performance = {
105      hints: 'warning',
106      maxEntrypointSize: 512000,
107      maxAssetSize: 512000,
108    };
109
110    config.optimization.runtimeChunk = false;
111  },
112  pluginOptions: {
113    i18n: {
114      localeDir: 'locales',
115      enableInSFC: true,
116    },
117  },
118};
119