forked from nsjcy/frontEnd/nsjcy

liuwh
2020-02-27 71c1fa3bfa21baaf733189495cdd64deb0cf6551
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const path = require("path");
const fs = require("fs");
 
const rules = [
  {
    test: /\.(js|jsx)$/i,
    loader: "babel-loader"
  },
  {
    test: /\.css$/i,
    use: [MiniCssExtractPlugin.loader, "css-loader"]
  },
  {
    test: /\.s[ac]ss$/i,
    use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
  },
  {
    test: /\.less$/i,
    use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"]
  },
  {
    test: /\.(svg|png|jpg|gif|ttf|css)$/i,
    loader: "file-loader",
    options: {
      name: "[name].[ext]?[hash]",
      outputPath: "static/"
    }
  }
];
 
const plugins = [
  new webpack.HotModuleReplacementPlugin(),
  new HtmlWebpackPlugin({
    template: "./src/conf/index.html",
    minify: true
  }),
  new MiniCssExtractPlugin({
    filename: "index.css?[hash]"
  })
];
 
if (fs.existsSync(path.resolve(__dirname, "./src/copy"))) {
  plugins.push(
    new CopyWebpackPlugin([
      {
        to: path.resolve(__dirname, "./dist-debug"),
        from: "./src/copy",
        toType: "dir"
      }
    ])
  );
}
 
module.exports = {
  entry: ["./src/conf/reset.scss", "./src/index.jsx", "./src/conf/cover.scss"],
  output: {
    path: path.resolve(__dirname, "./dist-debug"),
    filename: "index.js?[hash]"
  },
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"]
  },
  module: {
    rules
  },
  devServer: {
    contentBase: "./dist-debug",
    hot: true
  },
  mode: "development",
  devtool: "inline-source-map",
  plugins
};