-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.common.js
89 lines (87 loc) · 2.43 KB
/
webpack.common.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
"use strict";
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require("vue-loader");
const MyPlugin = require('./MyPlugin')
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
const path = require('path')
const webpack = require('webpack')
module.exports = {
entry: {
// 项目入口
main: './src/main.ts'
},
module: {
rules: [
// 编译vue单文件
{
test: /\.vue$/,
loader: 'vue-loader'
},
// 转化js的babel
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
// 处理图片
{
test: /\.(jpg|png|gif)$/,
use: {
loader: 'url-loader',
options: {
name: '[name]_[hash].[ext]',
outputPath: 'img/',
limit: 5000,
esModule: false
}
}
},
// 处理字体文件
{
test: /\.(eot|ttf|svg)$/,
use: {
loader: 'file-loader'
}
},
// 处理typeScript文件
{
test: /\.ts$/,
loader: 'ts-loader',
options: { appendTsSuffixTo: [/\.vue$/] }
},
]
},
plugins: [
// 基础路径URL
new webpack.DefinePlugin({
BASE_URL: '"/"'
}),
// vue plugin
new VueLoaderPlugin(),
// 模版文件
new HtmlWebpackPlugin({
template: './public/index.html',
title: 'vue3-ts-template'
}),
new FriendlyErrorsWebpackPlugin({
// 成功的时候输出
compilationSuccessInfo: {
messages: [`Your application is running here: http://localhost:8888`]
},
// 是否每次都清空控制台
clearConsole: true,
}),
new MyPlugin()
],
resolve: {
// 定义路径
alias: {
'@': path.join(__dirname, 'src')
},
// 入口文件后缀配置
extensions: ['.js', '.ts']
},
}