-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
84 lines (83 loc) · 2.58 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
const path = require('path')
const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
mode: 'development',
entry: "./src/index.js", // 指定入口文件,程序从这里开始编译,__dirname当前目录,
output: {
path: path.resolve(__dirname, './dist'), // 输出的路径
filename: 'bundle.js', // 打包后文件
},
// 添加需要解析的文件格式
resolve: {
extensions: ['.jsx', '.js', '.json'],
modules: [path.resolve(__dirname, 'node_modules')]
},
module: {
rules: [{
test: /\.(png|jpg|gif)$/,
use: [{
loader: 'file-loader',
options: {
limit: 5 * 1024,
//指定拷贝文件的输出目录
outputPath: 'images/'
}
}]
}, {
test: /\.css$/,
loader: "style-loader!css-loader?modules",
exclude: /node_modules/,
}, {
test: /\.scss$/,
use: ExtractTextWebpackPlugin.extract({
fallback: "style-loader",
use: ["css-loader", "sass-loader"],
publicPath: "./dist"
}),
include: path.join(__dirname, './src'),
exclude: /node_modules/
}, {
test: /\.(js|jsx)$/,
loader: 'babel-loader', // 加载器
exclude: /node_modules/,
query: {
presets: ["es2015", "react"],
plugins: [
["import", { libraryName: "antd", style: 'css' }] // antd按需加载
]
},
}, {//antd样式处理
test: /\.css$/,
exclude: /src/,
use: [
{ loader: "style-loader", },
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'learn-react',
template: './index.html',
}),
new ExtractTextWebpackPlugin({
filename: 'app.css',
allChunks: true
}),
],
devServer: {
contentBase: path.resolve(__dirname, "dist"),
// colors: true, //终端中输出结果为彩色
historyApiFallback: true, //不跳转
inline: true, //实时刷新
port: 8000,
},
devtool: 'source-map',
};