-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
103 lines (93 loc) · 2.51 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 CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const sourcePath = path.join(__dirname, 'src');
const destPath = path.join(__dirname, 'dist');
const targetBrowser = process.env.TARGET_BROWSER;
const prod = process.env.NODE_ENV === 'production';
module.exports = {
mode: prod ? 'production' : 'development',
entry: {
background: path.join(sourcePath, 'Background', 'background.ts'),
content: path.join(sourcePath, 'Content', 'content.ts'),
popup: path.join(sourcePath, 'Popup', 'popup.tsx'),
iframe: path.join(sourcePath, 'Content', 'Iframe', 'iframe.tsx'),
},
output: {
path: path.join(destPath, targetBrowser),
filename: 'js/[name].bundle.js',
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
use: 'ts-loader',
},
{
test: /\.css$/,
use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader'],
},
],
},
devtool: prod ? undefined : 'source-map',
plugins: [
new HtmlWebpackPlugin({
template: path.join(sourcePath, 'Popup', 'popup.html'),
inject: 'body',
chunks: ['popup'],
hash: true,
filename: 'popup.html',
}),
new HtmlWebpackPlugin({
template: path.join(sourcePath, 'Content', 'Iframe', 'iframe.html'),
inject: 'body',
chunks: ['iframe'],
hash: true,
filename: 'iframe.html',
}),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(process.env.npm_package_version),
}),
new MiniCssExtractPlugin(),
new CopyWebpackPlugin({
patterns: [{ from: 'src/assets', to: 'assets' }],
}),
new CopyWebpackPlugin({
patterns: [
{
from: `src/manifest.${targetBrowser}.json`,
to: './manifest.json',
},
],
}),
],
optimization: {
minimize: prod,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
compress: {
drop_console: true,
},
},
extractComments: false,
}),
],
},
stats: {
all: false,
builtAt: true,
errors: true,
hash: true,
},
};