text: // eslint-disable-next-line @typescript-eslint/no-var-requires
  const path = require('path')
  const CopyWebpackPlugin = require('copy-webpack-plugin')
  const webpack = require('webpack')
  
  // If your port is set to 80,
  // use administrator privileges to execute the command line.
  // For example, on Mac: sudo npm run / sudo yarn
  const name = 'Base Project' // page title
  const port = 9527 // dev port
  function resolve(dir) {
    return path.resolve(__dirname, dir)
  }
  
  module.exports = {
    publicPath: './',
    lintOnSave: process.env.NODE_ENV === 'development',
    productionSourceMap: false,
    devServer: {
      port: port,
      open: true,
      overlay: {
        warnings: false,
        errors: true
      },
      progress: false,
      proxy: {
        // change xxx-api/login => /mock-api/v1/login
        // detail: https://cli.vuejs.org/config/#devserver-proxy
        [process.env.VUE_APP_BASE_API]: {
          target: 'https://vue-typescript-admin-mock-server.armour.now.sh/mock-api/v1/',
          changeOrigin: true, // needed for virtual hosted sites
          ws: true, // proxy websockets
          pathRewrite: {
            ['^' + process.env.VUE_APP_BASE_API]: ''
          }
        }
      }
    },
    pwa: {
      name: name,
      workboxPluginMode: 'InjectManifest',
      workboxOptions: {
        swSrc: path.resolve(__dirname, 'src/pwa/service-worker.js')
      }
    },
    pluginOptions: {
      'style-resources-loader': {
        preProcessor: 'scss',
        patterns: [
          path.resolve(__dirname, 'src/styles/_variables.scss'),
          path.resolve(__dirname, 'src/styles/_mixins.scss')
        ]
      }
    },
    configureWebpack: {
      plugins: [
        // Copy Cesium Assets, Widgets, and Workers to a static directory
        new CopyWebpackPlugin({
          patterns: [
            { from: 'node_modules/cesium/Build/Cesium/Workers', to: 'Workers' },
            {
              from: 'node_modules/cesium/Build/Cesium/ThirdParty',
              to: 'ThirdParty'
            },
            { from: 'node_modules/cesium/Build/Cesium/Assets', to: 'Assets' },
            { from: 'node_modules/cesium/Build/Cesium/Widgets', to: 'Widgets' }
          ]
        }),
        new webpack.DefinePlugin({
          // Define relative base path in cesium for loading assets
          CESIUM_BASE_URL: JSON.stringify('')
        })
      ],
      module: {
        // Removes these errors: "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"
        // https://github.com/AnalyticalGraphicsInc/cesium-webpack-example/issues/6
        unknownContextCritical: false,
        unknownContextRegExp: /\/cesium\/cesium\/Source\/Core\/buildModuleUrl\.js/
      },
      externals: {
        echarts: 'echarts' // 配置使用CDN
      }
    },
    chainWebpack(config) {
      // provide the app's title in webpack's name field, so that
      // it can be accessed in index.html to inject the correct title.
      config.set('name', name)
  
      config.resolve.alias
        .set('@', resolve('src'))
  
      // it can improve the speed of the first screen, it is recommended to turn on preload
      config.plugin('preload').tap(() => [
        {
          rel: 'preload',
          // to ignore runtime.js
          // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
          fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
          include: 'initial'
        }
      ])
  
      // https://webpack.js.org/configuration/devtool/#development
      // Change development env source map if you want.
      // The default in vue-cli is 'eval-cheap-module-source-map'.
      // config
      //   .when(process.env.NODE_ENV === 'development',
      //     config => config.devtool('eval-cheap-source-map')
      //   )
  
      config
        .when(process.env.NODE_ENV !== 'development',
          config => {
            config
              .optimization.splitChunks({
                chunks: 'all',
                cacheGroups: {
                  libs: {
                    name: 'chunk-libs',
                    test: /[\\/]node_modules[\\/]/,
                    priority: 10,
                    chunks: 'initial' // only package third parties that are initially dependent
                  },
                  elementUI: {
                    name: 'chunk-elementUI', // split elementUI into a single package
                    priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                    test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                  },
                  commons: {
                    name: 'chunk-commons',
                    test: path.resolve(__dirname, 'src/components'),
                    minChunks: 3, //  minimum common number
                    priority: 5,
                    reuseExistingChunk: true
                  }
                }
              })
            // https://webpack.js.org/configuration/optimization/#optimizationruntimechunk
            config.optimization.runtimeChunk('single')
          }
        )
    }
  }
  