-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
89 lines (85 loc) · 2.01 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
86
87
88
89
/* eslint-env node */
/**************************
* @file: webpack配置
* @author: leinov
* @date: 2018-01-08
***************************/
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");//css分离打包
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");//js压缩
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); //css压缩
const HtmlWebpackPlugin = require("html-webpack-plugin");//生成html文件
//主配置
module.exports = (env, argv) => ({
entry: './src/index.js',
output: {
path: path.join(__dirname, "build"),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
{ "plugins": ["@babel/plugin-proposal-class-properties"] }
],
}
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /node_modules/,
},
{
test: /\.(scss|css)$/, //css打包 路径在plugins里
use: [
argv.mode == "development" ? { loader: "style-loader" } : MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { url: false, sourceMap: true } },
{ loader: "sass-loader", options: { sourceMap: true } }
],
exclude: /node_modules/,
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]',
options: {
publicPath: '/'
}
},
],
},
devServer: {
port: 3100,
open: true,
proxy: {
'/api': {
target:'http://localhost:9003',
changeOrigin: true,
secure: false
}
}
},
resolve: {
alias: {
src: path.resolve(__dirname, "src/"),
component: path.resolve(__dirname, "src/component/"),
store: path.resolve(__dirname, "src/store/"),
}
},
plugins: [
new HtmlWebpackPlugin({
title:"react-full-stack",
template: "./public/index.html",
}),
new MiniCssExtractPlugin()
],
optimization: {
}
});