forked from kanchenai/mango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (95 loc) · 3.66 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
90
91
92
93
94
95
96
97
98
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/main',
output: {
filename: "view_app.js",
path: path.resolve(__dirname, './dist')
},
module: {
rules: [
{
test: /\.css$/,//也可以是数组
exclude: path.resolve(__dirname, 'src/css'),
use: [MiniCssExtractPlugin.loader, 'css-loader'],
resolve: {}
},
{
test: /\.css$/,//也可以是数组
include: path.resolve(__dirname, 'src/css'),
use: [MiniCssExtractPlugin.loader, 'css-loader', "view-css-loader"],
resolve: {}
},
{
//匹配js,使用babel-loader进行代码转化
// test:/\.js$/,
// use:{
// loader: "babel-loader"
// }
},
{
test: [/\.html$/],
include: path.resolve(__dirname, 'src/html/'),
use: ["html-loader", "view-html-loader"],
},
// {
// test: [/\.html$/],
// include: path.resolve(__dirname,'src/test/'),
// use:["html-loader","view-html-loader"]
// },
{
test: [/\.png$/, /\.jpg$/, /\.jpeg$/, /\.gif$/],
include: path.resolve(__dirname, 'src/images-js/'),//exclude:可以显示在html中的图片;include:不能显示html的图片,可以使用import导入
use: {
loader: "file-loader",
options: {
name: "[contenthash:8].[ext]",
output: "imgs",
}
},
}
],
// noParse: /jquery/
},
resolve: {
alias: {
"@core": path.resolve(__dirname, "core"),
"@src": path.resolve(__dirname, "src"),
"@css": path.resolve(__dirname, "src/css"),
"@fragment": path.resolve(__dirname, "src/fragment"),
"@html": path.resolve(__dirname, "src/html"),
"@images": path.resolve(__dirname, "src/images"),
"@images-js": path.resolve(__dirname, "src/images-js"),//用在js赋值s图片
"@page": path.resolve(__dirname, "src/page"),
},//字符替换规则
mainFields: ['browser', 'main'],//编译版本匹配,没懂
extensions: ['.js', '.json', '.html'],//文件后缀比配
modules: ['node_modules'],//第三方模块位置
descriptionFiles: ['package.json'],//第三方模块描述
enforceExtension: false,
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new HtmlWebpackPlugin({
template: "./public/index.html",
filename: "index.html"
})
],
mode: "development",//运行环境:开发环境
// mode: "production",//运行环境:生产环境
performance: {
hints: 'error',//提示等级
maxAssetSize: 2 * 1024 * 1024, // 文件大小提示阈值,整数类型(以字节为单位)1M,超过这个大小,会提示
maxEntrypointSize: 2 * 1024 * 1024 // 文件大小性能阈值,整数类型(以字节为单位)1M,超过这个大小,打包失败
},
resolveLoader: {
modules: [path.resolve(__dirname, "./core/loader"), 'node_modules']
},
// devServer: {//一般使用默认
// }
//使用source-map直接调试es6代码
devtool: 'source-map',
}