xref: /openbmc/webui-vue/vue.config.js (revision 4afe2f76)
1const CompressionPlugin = require('compression-webpack-plugin');
2
3module.exports = {
4  css: {
5    loaderOptions: {
6      sass: {
7        prependData: () => {
8          const envName = process.env.VUE_APP_ENV_NAME;
9          const hasCustomStyles =
10            process.env.CUSTOM_STYLES === 'true' ? true : false;
11          if (hasCustomStyles && envName !== undefined) {
12            // If there is an env name defined, import Sass
13            // overrides.
14            // It is important that these imports stay in this
15            // order to make sure enviroment overrides
16            // take precedence over the default BMC styles
17            return `
18              @import "@/assets/styles/bmc/helpers";
19              @import "@/env/assets/styles/_${envName}";
20              @import "@/assets/styles/bootstrap/_helpers";
21            `;
22          } else {
23            // Include helper imports so single file components
24            // do not need to include helper imports
25
26            // BMC Helpers must be imported before Bootstrap helpers to
27            // take advantage of Bootstrap's use of the Sass !default
28            // statement. Moving this helper after results in Bootstrap
29            // variables taking precedence over BMC's
30            return `
31              @import "@/assets/styles/bmc/helpers";
32              @import "@/assets/styles/bootstrap/_helpers";
33            `;
34          }
35        }
36      }
37    }
38  },
39  devServer: {
40    https: true,
41    proxy: {
42      '/': {
43        target: process.env.BASE_URL,
44        onProxyRes: proxyRes => {
45          // This header is ignored in the browser so removing
46          // it so we don't see warnings in the browser console
47          delete proxyRes.headers['strict-transport-security'];
48        }
49      }
50    },
51    port: 8000
52  },
53  productionSourceMap: false,
54  configureWebpack: config => {
55    const envName = process.env.VUE_APP_ENV_NAME;
56    const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false;
57    const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false;
58
59    if (process.env.NODE_ENV === 'production') {
60      config.plugins.push(
61        new CompressionPlugin({
62          deleteOriginalAssets: true
63        })
64      );
65    }
66
67    if (envName !== undefined) {
68      if (hasCustomStore) {
69        // If env has custom store, resolve store module in src/main.js
70        config.resolve.alias['./store$'] = `./env/store/${envName}.js`;
71      }
72      if (hasCustomRouter) {
73        // If env has custom router, resolve router module in src/main.js
74        config.resolve.alias['./router$'] = `./env/router/${envName}.js`;
75      }
76    }
77  },
78  chainWebpack: config => {
79    if (process.env.NODE_ENV === 'production') {
80      config.plugins.delete('prefetch');
81      config.plugins.delete('preload');
82    }
83  },
84  pluginOptions: {
85    i18n: {
86      localeDir: 'locales',
87      enableInSFC: true
88    }
89  }
90};
91