-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
103 lines (101 loc) · 2.56 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
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const mode =
process.env.NODE_ENV === 'development' ? 'development' : 'production';
module.exports = {
mode: mode,
entry: {
popup: path.join(__dirname, 'src', 'ts', 'popup.ts'),
options: path.join(__dirname, 'src', 'ts', 'options.ts'),
content: path.join(__dirname, 'src', 'ts', 'content.ts'),
background: path.join(__dirname, 'src', 'ts', 'background.ts'),
},
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.html$/,
use: 'html-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
},
},
],
include: /\.module\.css$/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
exclude: /\.module\.css$/,
},
{
test: /.(jpg|jpeg|png|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
],
exclude: /node_modules/,
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'src', 'manifest.json'),
transform: function (content, absoluteFrom) {
return Buffer.from(
JSON.stringify({
...JSON.parse(content.toString()),
version: process.env.npm_package_version,
})
);
},
},
],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'html', 'popup.html'),
filename: 'popup.html',
chunks: ['popup'],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'html', 'options.html'),
filename: 'options.html',
chunks: ['options'],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'html', 'content.html'),
filename: 'content.html',
chunks: ['content'],
}),
],
resolve: {
extensions: ['.ts', '.js'],
},
devtool: false,
};