-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
85 lines (83 loc) · 1.99 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const paths = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist'),
popup: path.join(__dirname, 'src', 'popup'),
background: path.join(__dirname, 'src', 'background'),
contentScript: path.join(__dirname, 'src', 'contentScript'),
};
module.exports = {
entry: {
background: paths.background,
popup: paths.popup,
contentScripts: paths.contentScript,
},
output: {
path: paths.dist,
filename: '[name].js',
clean: true,
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
{
test: /\.(png|svg|jpe?g|gif)$/i,
type: 'asset/source',
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
localIdentName: '[name]_[local]__[hash:base64:5]',
},
},
},
'postcss-loader',
],
},
],
},
resolve: {
extensions: ['*', '.ts', '.tsx', '.js'],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: `${paths.src}/manifest.json`,
transform: (content) => {
const baseManifest = JSON.parse(content);
const manifest = {
...baseManifest,
version: process.env.npm_package_version,
description: process.env.npm_package_description,
};
return JSON.stringify(manifest, null, 2);
},
},
],
}),
new HtmlWebpackPlugin({
template: `${paths.popup}/index.html`,
filename: 'popup.html',
chunks: ['popup'],
}),
],
};