-
Notifications
You must be signed in to change notification settings - Fork 14
/
webpack.config.ts
131 lines (129 loc) · 3.61 KB
/
webpack.config.ts
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { resolve, posix } from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import { VueLoaderPlugin } from 'vue-loader'
import Components from 'unplugin-vue-components/webpack'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import type { Configuration } from 'webpack'
import AutoImport from 'unplugin-auto-import/webpack'
import webpack from 'webpack'
import CopyWebpackPlugin from 'copy-webpack-plugin'
function assetsPath(_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
? './static'
: 'static'
return posix.join(assetsSubDirectory, _path)
}
const mode: 'production' | 'development' =
(process.env.MODE as any) ?? 'development'
const config: Configuration = {
devtool: "source-map", // 启用sourceMap
mode,
entry: {
'background': resolve('src', 'pages/background'),
'content': resolve('src', 'pages/content'),
'option': resolve('src', 'pages/option'),
'popup': resolve('src', 'pages/popup'),
},
output: {
path: resolve(__dirname, './chrome'),
publicPath: './',
filename: '[name].main.js'
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'static': resolve('static'),
},
extensions: ['.ts', '.js', '.mjs', '.json'],
},
module: {
rules: [
{
test: /\.mjs$/i,
resolve: { byDependency: { esm: { fullySpecified: false } } },
},
{ test: /\.vue$/, loader: 'vue-loader' },
{
test: /\.m?[tj]s$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 100000,
name: assetsPath('img/[name].[hash:7].[ext]')
}
},
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },//less的loader
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },//scss的loader
],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
filename: 'popup.html',
template: 'src/pages/popup/popup.html',
inject: 'body',
chunks: ["popup"],
minify: { //压缩
removeComments: true,
collapseWhitespace: true,
}
}),
new webpack.DefinePlugin({
'__VUE_OPTIONS_API__': true,
'__VUE_PROD_DEVTOOLS__': false
}),
new HtmlWebpackPlugin({
filename: 'option.html',
template: 'src/pages/option/option.html',
inject: 'body',
chunks: ["option"],
minify: { //压缩
removeComments: true,
collapseWhitespace: true,
}
}),
new CopyWebpackPlugin([{
from: resolve(__dirname, 'src/manifest.json'),
to: ''
},
{
from: resolve(__dirname, 'static/'),
to: 'static/'
}
], {
copyUnmodified: true
}),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/ // .md
],
imports: [
'vue', {}
],
dts: 'src/types/auto-imports.d.ts',
resolvers: [],
eslintrc: {
enabled: false, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
}
}),
Components({
resolvers: [ElementPlusResolver({})],
dts: 'types/components.d.ts',
}),
],
}
export default config