text: const fs = require("fs");
  const path = require("path");
  const webpack = require("webpack");
  const TerserPlugin = require("terser-webpack-plugin");
  const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  const nodeExternals = require("webpack-node-externals");
  const HtmlWebpackPlugin = require("html-webpack-plugin");
  const { CleanWebpackPlugin } = require("clean-webpack-plugin");
  const postcssPresetEnv = require("postcss-preset-env");
  
  const resolve = dir => path.join(__dirname, ".", dir);
  const isProd = process.env.NODE_ENV === "production";
  const { version, name, description } = require("../package.json");
  const docsDir = path.join(process.cwd(), "docs");
  
  module.exports = {
    mode: "development",
    entry: { [name]: "./src/index.js" },
    devtool: "source-map",
    module: {
      rules: [
        {
          test: /\.md$/,
          use: "raw-loader"
        },
        {
          test: /\.(js|jsx)$/,
          exclude: /node_modules/,
          use: {
            loader: "babel-loader"
          }
        },
        {
          // 编译less
          test: /\.less$/,
          use: [
            "style-loader",
            {
              loader: "css-loader",
              options: {
                importLoaders: 1
              }
            },
            {
              loader: "postcss-loader"
            },
            {
              loader: "less-loader",
              options: {
                javascriptEnabled: true
              }
            }
          ]
        },
        {
          test: /\.(jpe?g|png|gif|ogg|mp3)$/,
          use: [
            {
              loader: "url-loader",
              options: {
                limit: 10 * 1000
              }
            }
          ]
        },
        {
          test: /\.(woff|svg|eot|ttf)\??.*$/,
          use: ["file-loader"]
        }
      ]
    },
    resolve: {
      enforceExtension: false,
      extensions: [".js", ".jsx", ".json", ".less", ".css"]
    },
    plugins: [
      new MiniCssExtractPlugin({
        filename: "static/css/[name].min.css",
        chunkFilename: "static/css/[name].chunk.css"
      }),
      //预览
      new HtmlWebpackPlugin({
        template: path.join(__dirname, "../public/index.html"), //指定要打包的html路径和文件名
        filename: "./index.html" //指定输出路径和文件名
      }),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NamedModulesPlugin(),
      new webpack.NoEmitOnErrorsPlugin()
    ],
    //压缩js
    optimization: {
      minimizer: [
        new TerserPlugin({
          cache: true,
          parallel: true,
          sourceMap: true
        }),
        new OptimizeCssAssetsPlugin({
          assetNameRegExp: /\.css\.*(?!.*map)/g, //注意不要写成 /\.css$/g
          cssProcessor: require("cssnano"),
          cssProcessorOptions: {
            discardComments: { removeAll: true },
            safe: true,
            autoprefixer: false
          },
          canPrint: true
        })
      ]
    }
  };
  