forked from nsjcy/frontEnd/nsjcy

liuwh
2020-04-27 4e44bc1fd7806a6c1611302120882b91d96640b5
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
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|ttf)$/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 CleanWebpackPlugin(['dist']),
  new MiniCssExtractPlugin({
    filename: "index.css?[hash]"
  })
];
 
if (fs.existsSync(path.resolve(__dirname, './src/copy'))) {
  plugins.push(new CopyWebpackPlugin([{
    to: path.resolve(__dirname, './dist'),
    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'),
    filename: 'index.js?[hash]'
  },
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"]
  },
  module: {
    rules
  },
  mode: 'production',
  devtool: 'none',
  plugins
};