-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (109 loc) · 2.62 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
99
100
101
102
103
104
105
106
107
108
109
110
111
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlguins = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { VueLoaderPlugin } = require('vue-loader');
module.exports = (env, argv) => ({
entry: {
main: { import: ['./src/main.ts'], dependOn: 'vendors' },
vendors: { import: ['vue', 'vue-router'] }
},
mode: argv.mode,
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
chunkFilename: '[name].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
module: {
rules: [
{
test: /\.ts(x?)$/,
include: path.resolve(__dirname, 'src'), // 缩小ts编译范围,提高构建速度
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
appendTsxSuffixTo: [/\.vue$/], // 支持vue中使用tsx语法
},
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.(js|jsx)$/,
include: path.resolve(__dirname, 'src'),
loader: 'babel-loader',
},
{
test: /\.(css|less)$/,
use: [
argv.mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'less-loader',
'postcss-loader',
],
},
{
test: /\.(png|jpg|svg|gif)$/i,
type: 'asset/resource',
parser: {
dataUrlCondition: {
maxSize: 100 * 1024,
},
},
generator: {
filename: 'images/[name][ext]',
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlguins({
template: './public/index.html',
title: 'popular application in Apple',
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
}),
new VueLoaderPlugin(),
],
optimization: {
splitChunks: {
chunks: 'all' // 支持同步与异步代码分割
},
runtimeChunk: true, // 减少entry chunk体积,提高页面加载速度
},
devServer: {
port: 8080,
host: 'localhost',
allowedHosts: 'all',
open: true,
historyApiFallback: true,
proxy: {
'/hk': {
target: 'https://itunes.apple.com',
changeOrigin: true,
pathRewrite: {
'^/hk': '/hk',
},
},
},
},
});