vue.config.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // vue.config.js
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const RemoveStrictPlugin = require('remove-strict-webpack-plugin')
  5. const fs = require('fs')
  6. const SentryPlugin = require('@sentry/webpack-plugin')
  7. const TerserPlugin = require('terser-webpack-plugin')
  8. const merge = require('webpack-merge')
  9. const VueConfigPages = require('./vue.config.pages')
  10. const ImageminPlugin = require('imagemin-webpack-plugin').default
  11. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  12. const CompressionPlugin = require('compression-webpack-plugin')
  13. const exportEnv = require('./src/helpers/export-env')
  14. const os = require('os')
  15. const devMode = process.env.NODE_ENV !== 'production'
  16. const publicPath = process.env.VUE_APP_PUBLIC_PATH || false
  17. const sourceMap = process.env.VUE_APP_ENABLE_SOURCEMAP ? process.env.VUE_APP_ENABLE_SOURCEMAP === 'true' : false
  18. const devTool = process.env.VUE_APP_DEVTOOL ? process.env.VUE_APP_DEVTOOL : 'cheap-source-map'
  19. const isEvo = process.env.VUE_APP_APPLICATION_NAME === 'EVO'
  20. const pwaConfigs = {
  21. manifestPath: isEvo ? 'evo-manifest.json' : 'ibs-manifest.json',
  22. manifestOptions: require(`./public/${isEvo ? 'evo' : 'ibs'}-manifest.json`),
  23. }
  24. function resolve(dir) {
  25. return path.join(__dirname, dir)
  26. }
  27. module.exports = {
  28. // Vue cli MultiPage setup
  29. publicPath: !devMode && publicPath ? publicPath : '/',
  30. pages: VueConfigPages.getPages(),
  31. productionSourceMap: true,
  32. configureWebpack: config => {
  33. config = {
  34. devtool: devTool,
  35. resolve: {
  36. // load vue-loader read .js .vue .json files
  37. extensions: ['.js', '.vue', '.json'],
  38. // add alias
  39. alias: {
  40. vue$: 'vue/dist/vue.esm.js',
  41. '@': resolve('src'),
  42. '@@': resolve('src/thirdparty/eshop'),
  43. '@@@': resolve('src/thirdparty/placement-tree-viewer'),
  44. '@@@@': resolve('src/thirdparty/payment'),
  45. '@AppCenter': resolve('src/thirdparty/elken-app-center'),
  46. vue: 'vue/dist/vue.esm.js',
  47. },
  48. },
  49. // use jquery
  50. plugins: [
  51. new exportEnv({ filename: 'env-vars.js' }),
  52. new webpack.ProvidePlugin({
  53. $: 'jquery',
  54. jquery: 'jquery',
  55. 'window.jQuery': 'jquery',
  56. jQuery: 'jquery',
  57. }),
  58. new ImageminPlugin({
  59. test: /\.(jpe?g|png|gif|svg)$/i,
  60. disable: devMode,
  61. }),
  62. new MiniCssExtractPlugin({
  63. filename: devMode ? '[name].css' : '[name].[hash].css',
  64. chunkFilename: devMode ? '[name].[id].css' : '[name].[id].[hash].css',
  65. }),
  66. ],
  67. }
  68. // Development -----------------------------------------------------------------------------------------------------
  69. if (devMode) {
  70. config.devServer = {
  71. host: process.env.VUE_APP_HOST || '0.0.0.0',
  72. port: process.env.VUE_APP_PORT || '8080',
  73. open: true,
  74. disableHostCheck: true,
  75. hot: true,
  76. inline: false,
  77. // Todo enabled if history mode
  78. // historyApiFallback: {
  79. // rewrites: [
  80. // { from: /^\/products\/?.*/, to: path.posix.join('/', '/products/index.html') },
  81. // { from: /^\/checkout\/?.*/, to: path.posix.join('/', '/checkout/index.html') },
  82. // { from: /./, to: path.posix.join('/', 'index.html') },
  83. // ],
  84. // },
  85. allowedHosts: [process.env.VUE_APP_HOST],
  86. }
  87. if (process.env.VUE_APP_HTTPS === 'true') {
  88. config.devServer = merge(config.devServer, {
  89. https: {
  90. key: fs.readFileSync(resolve('certs/localhost.key'), 'utf8'),
  91. cert: fs.readFileSync(resolve('certs/localhost.crt'), 'utf8'),
  92. },
  93. })
  94. }
  95. }
  96. // PRODUCTION ------------------------------------------------------------------------------------------------------
  97. if (!devMode) {
  98. config.optimization = {
  99. // minimize: false, // Enable to debug code in production
  100. minimizer: [
  101. new TerserPlugin({
  102. sourceMap: sourceMap,
  103. parallel: true,
  104. extractComments: true,
  105. cache: true,
  106. terserOptions: {
  107. output: {
  108. comments: false,
  109. },
  110. safari10: true,
  111. compress: {
  112. inline: 0,
  113. },
  114. mangle: false,
  115. },
  116. }),
  117. ],
  118. }
  119. config.plugins.push(
  120. // Remove strict on build. Support for safari 8 or old browsers
  121. new RemoveStrictPlugin()
  122. )
  123. }
  124. // enable gzip (experimental)
  125. if (process.env.VUE_APP_ENABLE_GZIP === 'true') {
  126. config.plugins.push(
  127. new CompressionPlugin({
  128. filename: '[path].gz[query]',
  129. algorithm: 'gzip',
  130. test: /\.(js|css|html|svg)$/,
  131. cache: true,
  132. minRatio: 0.6,
  133. compressionOptions: { level: 11 },
  134. })
  135. )
  136. }
  137. // add sentry login
  138. if (process.env.VUE_APP_LOG_SENTRY === 'true') {
  139. config.plugins.push(
  140. new SentryPlugin({
  141. release: require(path.join(__dirname, '/package.json')).version,
  142. include: './dist',
  143. ignore: ['node_modules', 'webpack.config.js'],
  144. })
  145. )
  146. }
  147. return config
  148. },
  149. chainWebpack: config => {
  150. // Webpack chunks optimizations
  151. config.optimization.splitChunks({
  152. cacheGroups: VueConfigPages.getPagesSplitChunkCacheGroupsOptimizations(),
  153. })
  154. // Change the sass loader from vue-style-loader to fast-sass-loader for build
  155. // performance, however fast-sass-loader dose this by merging all the code into
  156. // one file and caching the file. Which leverages the ability to produce
  157. // sourcemaps
  158. config.module.rules.delete('scss')
  159. let scssRule = config.module.rule('scss').test(/\.scss$/)
  160. ;[
  161. { name: MiniCssExtractPlugin.loader },
  162. { name: 'css-loader' },
  163. { name: 'postcss-loader' },
  164. { name: 'fast-sass-loader' },
  165. ].forEach(load => {
  166. scssRule
  167. .use(load.name)
  168. .loader(load.loader || load.name)
  169. .options(load.options || {})
  170. })
  171. // GraphQL Loader to dynamically generate responsive images
  172. config.module
  173. .rule('responsive-loader')
  174. .test(/\.(jpe?g|png)\?$/i)
  175. .use('responsive-loader')
  176. .loader('responsive-loader')
  177. .end()
  178. // Remove the default typescript loader to allow .ts and .js to co-exist
  179. const rule = config.module.rule('ts')
  180. rule.uses.delete('thread-loader')
  181. rule
  182. .use('ts-loader')
  183. .loader('ts-loader')
  184. .tap(options => {
  185. options.transpileOnly = false
  186. options.happyPackMode = false
  187. return options
  188. })
  189. if (!devMode) {
  190. // remove type checking on production
  191. config.plugins.delete('fork-ts-checker')
  192. } else {
  193. // increase memory for type checking on dev
  194. config.plugin('fork-ts-checker').tap(args => {
  195. let totalmem = Math.floor(os.totalmem() / 1024 / 1024) //get OS mem size
  196. args[0].memoryLimit = totalmem > 4200 ? 4096 : 2048
  197. return args
  198. })
  199. }
  200. },
  201. transpileDependencies: [
  202. 'bootstrap-vue', // not being transpile to ES5 causes failing in Safari 8
  203. 'vue-bootstrap-slider', // not being transpile to ES5 causes failing in Safari 8
  204. ],
  205. css: {
  206. // sourceMap: process.env.NODE_ENV === 'development' && process.env.VUE_APP_CSS_SOURCE_MAP !== 'false',
  207. loaderOptions: {
  208. // pass options to sass-loader
  209. sass: {
  210. // @/ is an alias to src/
  211. // so this assumes you have a file named `src/variables.scss`
  212. data: ``,
  213. sassOptions: {
  214. outputStyle: 'compressed',
  215. },
  216. },
  217. },
  218. },
  219. pwa: {
  220. themeColor: '#071241',
  221. msTileColor: '#071241',
  222. appleMobileWebAppCapable: 'yes',
  223. workboxPluginMode: 'InjectManifest',
  224. workboxOptions: {
  225. swSrc: 'src/service-worker.js',
  226. exclude: [/\.map$/, /manifest\.json$/, '.htaccess', '.gitkeep', 'gitignore'],
  227. },
  228. ...pwaConfigs,
  229. },
  230. }