xref: /openbmc/webui-vue/vue.config.js (revision 8c4bb44c)
1const CompressionPlugin = require('compression-webpack-plugin');
2const webpack = require('webpack');
3const LimitChunkCountPlugin = webpack.optimize.LimitChunkCountPlugin;
4
5module.exports = {
6  css: {
7    loaderOptions: {
8      sass: {
9        prependData: () => {
10          const envName = process.env.VUE_APP_ENV_NAME;
11          const hasCustomStyles =
12            process.env.CUSTOM_STYLES === 'true' ? true : false;
13          if (hasCustomStyles && envName !== undefined) {
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";
21              @import "@/env/assets/styles/_${envName}";
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          }
37        },
38      },
39    },
40  },
41  devServer: {
42    https: true,
43    proxy: {
44      '/': {
45        target: process.env.BASE_URL,
46        onProxyRes: (proxyRes) => {
47          // This header is ignored in the browser so removing
48          // it so we don't see warnings in the browser console
49          delete proxyRes.headers['strict-transport-security'];
50        },
51      },
52    },
53    port: 8000,
54  },
55  productionSourceMap: false,
56  chainWebpack: (config) => {
57    config.module
58      .rule('vue')
59      .use('vue-svg-inline-loader')
60      .loader('vue-svg-inline-loader');
61    config.module
62      .rule('ico')
63      .test(/\.ico$/)
64      .use('file-loader')
65      .loader('file-loader')
66      .options({
67        name: '[name].[contenthash:8].[ext]',
68      });
69    config.plugins.delete('preload');
70    if (process.env.NODE_ENV === 'production') {
71      config.plugin('html').tap((options) => {
72        options[0].filename = 'index.[hash:8].html';
73        return options;
74      });
75    }
76  },
77  configureWebpack: (config) => {
78    config.plugins.push(
79      new LimitChunkCountPlugin({
80        maxChunks: 1,
81      }),
82    );
83    config.optimization.splitChunks = {
84      cacheGroups: {
85        default: false,
86      },
87    };
88    const crypto = require('crypto');
89    const crypto_orig_createHash = crypto.createHash;
90    crypto.createHash = (algorithm) =>
91      crypto_orig_createHash(algorithm == 'md4' ? 'sha256' : algorithm);
92
93    const envName = process.env.VUE_APP_ENV_NAME;
94    const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
95    const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
96    const hasCustomAppNav =
97      process.env.CUSTOM_APP_NAV === 'true' ? true : false;
98
99    if (envName !== undefined) {
100      if (hasCustomStore) {
101        // If env has custom store, resolve all store modules. Currently found
102        // in src/router/index.js src/store/api.js and src/main.js
103        config.resolve.alias['./store$'] = `@/env/store/${envName}.js`;
104        config.resolve.alias['../store$'] = `@/env/store/${envName}.js`;
105      }
106      if (hasCustomRouter) {
107        // If env has custom router, resolve routes in src/router/index.js
108        config.resolve.alias['./routes$'] = `@/env/router/${envName}.js`;
109      }
110      if (hasCustomAppNav) {
111        // If env has custom AppNavigation, resolve AppNavigationMixin module in src/components/AppNavigation/AppNavigation.vue
112        config.resolve.alias['./AppNavigationMixin$'] =
113          `@/env/components/AppNavigation/${envName}.js`;
114      }
115    }
116
117    if (process.env.NODE_ENV === 'production') {
118      config.plugins.push(
119        new CompressionPlugin({
120          deleteOriginalAssets: true,
121        }),
122      );
123    }
124
125    config.performance = {
126      hints: 'warning',
127      maxEntrypointSize: 512000,
128      maxAssetSize: 512000,
129    };
130
131    config.optimization.runtimeChunk = false;
132  },
133  pluginOptions: {
134    i18n: {
135      localeDir: 'locales',
136      enableInSFC: true,
137    },
138  },
139};
140