forked from nsjcy/frontEnd/nsjcy

LAPTOP-RI7D261L\Mr Ke
2020-02-04 d25d5769416fbb2e861e8f434c5a6770ff69c482
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-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: /\.(svg|png|jpg|gif)$/i,
  loader: 'file-loader',
  options: {
    name: '[name].[ext]?[hash]',
    outputPath: 'static/'
  }
}];
 
 
const plugins = [
  new webpack.HotModuleReplacementPlugin(),
  new HtmlWebpackPlugin({
    template: path.resolve(__dirname, './Delivery/desktop/src/conf/home.html'),
    filename: 'home.html',
    chunks: ['home'],
    minify: true
  }),
  new HtmlWebpackPlugin({
    template: path.resolve(__dirname, './Delivery/desktop/src/conf/login.html'),
    filename: 'login.html',
    chunks: ['login'],
    minify: true
  }),
  new HtmlWebpackPlugin({
    template: path.resolve(__dirname, './Delivery/desktop/src/conf/ems.html'),
    filename: 'ems.html',
    chunks: ['ems'],
    minify: true
  }),
  new CleanWebpackPlugin(['dist'], {
    root: path.resolve(__dirname, './Delivery/desktop')
  }),
  new MiniCssExtractPlugin({
    filename: "[name].css?[hash]"
  })
];
 
if (fs.existsSync(path.resolve(__dirname, './Delivery/desktop/src/copy'))) {
  plugins.push(new CopyWebpackPlugin([{
    to: path.resolve(__dirname, './Delivery/desktop/dist'),
    from: './Delivery/desktop/src/copy',
    toType: 'dir'
  }]));
}
 
 
module.exports = {
  entry: {
    home: [
      './Delivery/desktop/src/conf/reset.scss',
      './Delivery/desktop/src/home.jsx',
      './Delivery/desktop/src/conf/cover.scss'
    ],
    login: [
      './Delivery/desktop/src/conf/reset.scss',
      './Delivery/desktop/src/login.jsx',
      './Delivery/desktop/src/conf/cover.scss'
    ],
    ems: [
      './Delivery/desktop/src/conf/reset.scss',
      './Delivery/desktop/src/ems.jsx',
      './Delivery/desktop/src/conf/cover.scss'
    ]
  },
  output: {
    path: path.resolve(__dirname, './Delivery/desktop/dist'),
    filename: '[name].js?[hash]'
  },
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"]
  },
  module: {
    rules
  },
  mode: 'production',
  devtool: 'none',
  plugins
};