-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.js
181 lines (170 loc) · 4.45 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const webpack = require('webpack');
const process = require('process');
const { resolve } = require('path');
const autoprefixer = require('autoprefixer');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('./manifestPlugin');
const devMode = process.env.NODE_ENV !== 'production';
const isDesktop = process.env.PURPOSE === 'desktop';
const plugins = [
new webpack.DefinePlugin({
'process.env.isDesktop': isDesktop,
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new HtmlWebpackPlugin({
chunks: ['popup'],
template: `${resolve(__dirname, 'src', 'popup')}/popup.html`,
filename: `${resolve(`${__dirname}/dist`)}/popup.html`,
}),
new HtmlWebpackPlugin({
chunks: ['interaction'],
template: `${resolve(
__dirname,
'src',
'interaction',
)}/interaction.html`,
filename: `${resolve(`${__dirname}/dist`)}/interaction.html`,
}),
new ManifestPlugin(),
];
const optimization = {
minimizer: [
new HtmlMinimizerPlugin(),
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
}),
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: 'async', // Only split async (dynamic) imports
cacheGroups: {
// Disable any default cache groups
default: false,
vendors: false,
},
},
runtimeChunk: false, // No runtime chunk should be created
};
const fallback = {
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
};
const entry = {
popup: resolve(`${__dirname}/src/popup/index.tsx`),
background_script: resolve(
`${__dirname}/src/background_script/index.js`,
),
content_script: resolve(`${__dirname}/src/content_script/index.js`),
client_script: resolve(`${__dirname}/src/client_script/index.js`),
interaction: resolve(`${__dirname}/src/interaction/index.jsx`),
};
if (isDesktop) {
entry.electron = resolve(`${__dirname}/src/electron.js`);
}
if (!isDesktop) {
optimization.splitChunks = false;
// chunks: 'all',
// };
}
if (!devMode) {
plugins.push(new MiniCssExtractPlugin());
}
const config = {
entry,
output: {
filename: '[name].js',
path: resolve(`${__dirname}/dist`),
},
optimization,
module: {
rules: [
{
test: /\.tsx?/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(css|less)$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: 'global',
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins() {
return [autoprefixer];
},
},
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
},
{
test: /\.(png|jpg|jpeg|gif|woff|woff2|ttf|eot|svg)$/,
type: 'asset/resource',
},
],
},
plugins,
resolve: {
fallback,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
src: resolve(__dirname, 'src'),
popup: resolve(__dirname, 'src', 'popup'),
helpers: resolve(__dirname, 'src', 'helpers'),
assets: resolve(__dirname, 'src', 'assets'),
background_script_bundle: devMode
? 'dist/vendors-node_modules_aes256_index_js-node_modules_babel-polyfill_lib_index_js-node_modules_st-aa6ffa.js'
: 'dist/686.js',
},
},
watch: devMode,
target: isDesktop ? 'electron-renderer' : 'web',
};
if (devMode) {
config.devtool = 'source-map';
}
module.exports = config;