const path = require('path');

const params = {
  context: path.resolve(__dirname, '../src'),
  mode: 'development',
  watch: true,
  entry: path.resolve(__dirname, '../src/tests/index.tsx'),
  output: {
    path: path.resolve(__dirname, '../preview'),
    filename: '[name].[contenthash].bundle.js',
    chunkFilename: '[name].[contenthash].chunk.js',
    publicPath: '/',
    pathinfo: false,
  },
  htmlTemplatePath: path.resolve(__dirname, '../template/index.html'),
  externals: {
    react: 'window.React',
    'react-dom': 'window.ReactDOM',
    mobx: 'window.mobx',
    '@cloudbase/js-sdk': 'window.cloudbase',
    '@cloudbase/weda-cloud-sdk': 'window.CloudSDK',
    '@cloudbase/weda-cloud-sdk/dist/h5': 'window.CloudSDK',
    '@zxing/library': 'window.ZXing',
    '@babel/standalone': 'window.Babel',
    '@cloudbase/lowcode-render': 'window["weda-render"]',
  },
  definePlugin: {},
  optimization: {
    splitChunks: {
      cacheGroups: {
        base: {
          test: /(react|react-dom|react-router|react-router-dom|mobx|mobx-react-lite|@cloudbase\/js-sdk)/,
          chunks: 'all',
          priority: 100, // 优先级
        },
        utils: {
          test: /(lodash|dayjs|axios|kbone-api|fastclick)/,
          chunks: 'all',
          priority: 100, // 优先级
        },
        'async-commons': {
          chunks: 'async',
          minChunks: 2,
          priority: 20,
        },
        commons: {
          chunks: 'all',
          minChunks: 2,
          priority: 20,
        },
      },
    },
  },
};

module.exports = require('./web.prod.js')(params);
