-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
108 lines (106 loc) · 3.13 KB
/
Copy pathwebpack.config.js
File metadata and controls
108 lines (106 loc) · 3.13 KB
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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { EnvironmentPlugin } = require('webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
const { version } = require('./package.json');
module.exports = (env) => ({
mode: env?.development ? 'development' : 'production',
entry: {
content: `${__dirname}/src/content/index.tsx`,
popup: `${__dirname}/src/popup/index.tsx`,
},
output: {
publicPath: '',
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
clean: true,
},
devtool: env?.development ? 'cheap-module-source-map' : false,
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
loader: 'url-loader',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.less$/i,
use: ['style-loader', 'css-loader', 'less-loader'],
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
plugins: [
new TsconfigPathsPlugin({
extensions: ['.ts', '.tsx', '.js', '.jsx'],
}),
],
alias: {
react: path.resolve('./node_modules/react'),
},
},
plugins: [
new EnvironmentPlugin([]),
new CopyWebpackPlugin({
patterns: [
{
from: `./src/manifest${
env?.platform === 'opera' ? 'Opera' : ''
}.json`,
to: 'manifest.json',
force: true,
},
{
from: './src/_locales',
to: '_locales',
force: true,
},
{
from: './src/popup/popup.html',
to: 'popup.html',
force: true,
},
{
context: './src/assets/icons',
from: '*.png',
to: 'icons',
force: true,
},
],
}),
new ZipPlugin({
path: path.resolve(__dirname, 'release'),
filename:
env?.platform === 'opera'
? `build-opera-${version}.zip`
: `build-chrome-${version}.zip`,
}),
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
});