forked from 2662419405/AllDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
85 lines (84 loc) · 2.36 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
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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
//指定打包的入口文件
mode: "development",
entry: "./index.js",
//指定打包后的资源位置
output: {
//公共路径设置
//publicPath: "https://cdn.baidu.com",
path: path.resolve(__dirname, "./build"),
filename: "index.js"
},
devtool: "cheap-module-eval-source-map",
module: {
//遇到不认识的模块就在这里找loader解决
rules: [
{
test: /\.(png|jpe?g|gif)$/,
use: {
//url-loader 可以限定模块的体积,根据体积判断是否需要转换成base64,减少http请求
loader: "url-loader", //file-loader就是把模块,放在另外一个目录里,并且把位置返回给我们,第三方字体
options: {
// name是打包前模块的名称,ext是打包前的模块格式
name: "[name]_[hash].[ext]",
outputPath: "images/",
limit: 15500
}
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"]
},
{
test: /\.scss$/, //loader是有执行顺序,从后往前
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.js/, //babel转化es6到es5
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
// presets: [
// [
// "@babel/preset-env",
// {
// useBuiltIns: "usage",
// corejs: 2
// }
// ]
// ],
plugins: ["@babel/plugin-transform-runtime"]
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html",
title: "标题-自己取的"
// filename: "app.html"
}),
//在打包之前,先帮我们把生成目录删除一下
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
})
],
devServer: {
contentBase: "./build",
open: true,
port: "8081",
proxy: {
"/api": {
target: "http://localhost:9092"
}
}
}
};