-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
53 lines (50 loc) · 1.38 KB
/
webpack.config.js
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
const path = require("path");
const currentTask = process.env.npm_lifecycle_event;
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require("html-webpack-plugin")
const {CleanWebpackPlugin} = require("clean-webpack-plugin")
const {WebpackManifestPlugin} = require("webpack-manifest-plugin")
const config = {
entry: "./src/index.js",
output: {
filename: "bundle.[hash].js",
path: path.resolve(__dirname, "dist"),
},
devServer: {
port: 8080,
static: {
directory: path.resolve(__dirname, "dist"),
},
compress: true,
hot: true,
},
plugins: [new HtmlWebpackPlugin({ template: "./src/index.html" })],
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-react"],
},
},
},
{
test: /\.(scss|css)$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
],
},
mode: "development",
};
if(currentTask == "build"){
config.mode = "production"
config.module.rules[1].use[0] = MiniCssExtractPlugin.loader
config.plugins.push(new MiniCssExtractPlugin({ filename: "main.[hash].css" }), new CleanWebpackPlugin(), new WebpackManifestPlugin({}))
}
module.exports = config