This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
86 lines (81 loc) · 2.07 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
import path from 'path'
import webpack from 'webpack'
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin'
import CopyPlugin = require('copy-webpack-plugin')
const isDevelopment = process.env.NODE_ENV !== 'production'
const sourceDirectory = path.join(__dirname, 'src')
const outputDirectory = path.join(__dirname, 'dist')
const webpackConfig: webpack.Configuration = {
watch: isDevelopment,
mode: isDevelopment ? 'development' : 'production',
devtool: 'inline-source-map',
entry: {
'popup': path.join(sourceDirectory, 'popup/index.ts'),
'content': [
path.join(sourceDirectory, 'content/index.ts'),
// https://github.com/pacexy/mv3-hot-reload#1-inject-the-code-for-hot-reloading
...(isDevelopment ? ['mv3-hot-reload/content'] : []),
],
'service-worker': [
path.join(sourceDirectory, 'service-worker/index.ts'),
...(isDevelopment ? ['mv3-hot-reload/background'] : []),
],
},
output: {
path: outputDirectory,
filename: '[name].js',
clean: true,
},
module: {
rules: [
{
test: /\.css$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
exportLocalsConvention: 'camelCase',
},
},
},
'postcss-loader',
],
},
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
plugins: [new TsconfigPathsPlugin()],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(sourceDirectory, 'popup/popup.html'),
to: path.resolve(outputDirectory, 'popup.html'),
},
{
from: path.resolve(sourceDirectory, 'manifest.json'),
to: path.resolve(outputDirectory, 'manifest.json'),
},
{
from: path.resolve(sourceDirectory, 'assets'),
to: path.resolve(outputDirectory),
},
],
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.MV3_HOT_RELOAD_PORT': JSON.stringify(process.env.MV3_HOT_RELOAD_PORT ?? null),
}),
],
}
export default webpackConfig