Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path')
  2. const webpack = require('webpack')
  3.  
  4. const src = path.resolve(__dirname, 'src')
  5.  
  6. const options = {
  7.   enableOptimization: false
  8. }
  9.  
  10. module.exports = env => {
  11.   const getEnvVar = v => {
  12.     return env ? env[v] : undefined
  13.   }
  14.   const getEnvVarStr = v => {
  15.     return env ? JSON.stringify(env[v]) : undefined
  16.   }
  17.  
  18.   const base = {
  19.     entry: {
  20.       enumListEditor: src + '/enum-list-editor/index.js',
  21.       projectTab: src + '/project-tab/index.js',
  22.       pivot: src + '/pivot/index.js'
  23.     },
  24.     output: {
  25.       path: path.resolve(__dirname, '../backend/src/main/resources/client'),
  26.       filename: '[name].bundle.js'
  27.     },
  28.     module: {
  29.       rules: [
  30.         {
  31.           test: /\.js$/,
  32.           exclude: /node_modules/,
  33.           loader: ['babel-loader', 'eslint-loader']
  34.         },
  35.         {
  36.           test: /\.css$/,
  37.           use: ['style-loader', 'css-loader']
  38.         }
  39.       ]
  40.     },
  41.     plugins: [
  42.       new webpack.DefinePlugin({
  43.         LOCAL: false
  44.       })
  45.     ]
  46.   }
  47.  
  48.   const dev = {
  49.     devServer: {
  50.       contentBase: path.resolve(__dirname, 'html'),
  51.       publicPath: '/',
  52.       compress: true,
  53.       port: 8081,
  54.       proxy: {
  55.         '/jira-server': {
  56.           target: getEnvVar('server'),
  57.           pathRewrite: { '^/jira-server': '' },
  58.           changeOrigin: true
  59.         }
  60.       }
  61.     },
  62.     plugins: [
  63.       new webpack.DefinePlugin({
  64.         LOCAL: getEnvVar('local'),
  65.         USERNAME: getEnvVarStr('user'),
  66.         PASSWORD: getEnvVarStr('password')
  67.       })
  68.     ]
  69.   }
  70.  
  71.   const prod = {
  72.   }
  73.  
  74.   //  это можно заменить react-loadable
  75.   const optimization = {
  76.     plugins: [
  77.       new webpack.HashedModuleIdsPlugin()
  78.     ],
  79.     optimization: {
  80.       runtimeChunk: 'single',
  81.       splitChunks: {
  82.         chunks: 'all',
  83.         maxInitialRequests: Infinity,
  84.         minSize: 0,
  85.         cacheGroups: {
  86.           vendor: {
  87.             test: /[\\/]node_modules[\\/]/,
  88.             name (module) {
  89.               // get the name. E.g. node_modules/packageName/not/this/part.js
  90.               // or node_modules/packageName
  91.               const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
  92.  
  93.               // npm package names are URL-safe, but some servers don't like @ symbols
  94.               return `npm.${packageName.replace('@', '')}`
  95.             }
  96.           }
  97.         }
  98.       }
  99.     }
  100.   }
  101.  
  102.   //  собираем
  103.   let conf = env && env.local ? { ...base, ...dev } : { ...base, ...prod }
  104.  
  105.   conf = options.enableOptimization ? { ...conf, ...optimization } : conf
  106.  
  107.   return conf
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement