/*
 * @Author: wangdengzhi
 * @Date: 2020-08-19 15:32:32
 * @Last Modified by: wangdengzhi
 * @Last Modified time: 2020-08-24 09:09:53
 * @description: 开发环境配置，将文件打包到dist目录，使用devServer启动热更新
 * 使用theme变量切换和调试主题
 * 直接调试本地代码
 */
const { merge } = require('webpack-merge');
const common = require('./webpack.common');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const smp = new SpeedMeasurePlugin();
const webpack = require('webpack');

module.exports = smp.wrap(
  merge(common, {
    entry: {
      app: path.resolve(__dirname, '../../page/mock/index.tsx'),
    },
    mode: 'development',
    devtool: 'inline-source-map',
    devServer: {
      contentBase: path.join(__dirname, '../../dist'),
      compress: true,
      port: 9002,
      hot: true,
    },
    plugins: [
      new webpack.DefinePlugin({
        webpack_theme: JSON.stringify('android'), // 开发环境通过指定全局变量完成主题设置
      }),
      new HtmlWebpackPlugin({
        template: path.resolve(__dirname, '../../template/index.html'),
        filename: path.resolve(__dirname, '../../dist/index.html'),
        chunks: ['app', 'common'],
      }),
    ],
  })
);
