text: const { resolve } = require('path')
  // const { PROJECT_PATH } = require('../constants')
  const { isDev, PROJECT_PATH } = require('../constants')
  
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  
  module.exports = {
    entry: {
      app: resolve(PROJECT_PATH, './src/index.tsx'),
    },
    output: {
      // filename: 'js/[name].[hash:8].js',
      filename: `js/[name]${isDev ? '' : '.[hash:8]'}.js`,
      path: resolve(PROJECT_PATH, './dist'),
    },
    resolve: {
      extensions: ['.tsx', '.ts', '.js', '.json'],
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: resolve(PROJECT_PATH, './public/index.html'),
        filename: 'index.html',
        cache: false, // 特别重要：防止之后使用v6版本 copy-webpack-plugin 时代码修改一刷新页面为空问题。
        minify: isDev
          ? false
          : {
              removeAttributeQuotes: true,
              collapseWhitespace: true,
              removeComments: true,
              collapseBooleanAttributes: true,
              collapseInlineTagWhitespace: true,
              removeRedundantAttributes: true,
              removeScriptTypeAttributes: true,
              removeStyleLinkTypeAttributes: true,
              minifyCSS: true,
              minifyJS: true,
              minifyURLs: true,
              useShortDoctype: true,
            },
      }),
    ],
    module: {
      rules: [
        {
          test: /\.(tsx?|js)$/,
          loader: 'babel-loader',
          options: { cacheDirectory: true },
          exclude: /node_modules/,
        },
        {
          test: /\.css$/,
          use: [
            'style-loader',
            {
              loader: 'css-loader',
              options: {
                modules: false, // 默认就是 false, 若要开启，可在官网具体查看可配置项
                sourceMap: isDev, // 开启后与 devtool 设置一致, 开发环境开启，生产环境关闭
                importLoaders: 0, // 指定在 CSS loader 处理前使用的 laoder 数量
              },
            },
          ],
        },
        {
          test: /\.scss$/,
          use: [
            'style-loader',
            {
              loader: 'css-loader',
              options: {
                modules: false,
                sourceMap: isDev,
                importLoaders: 1, // 需要先被 sass-loader 处理，所以这里设置为 1
              },
            },
            {
              loader: 'sass-loader',
              options: {
                sourceMap: isDev,
              },
            },
          ],
        },
      ],
    },
  }
  