Repository navigation
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
102 lines (98 loc) · 2.49 KB
/
Copy pathwebpack.config.ts
File metadata and controls
102 lines (98 loc) · 2.49 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
import CopyPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import path from 'path';
import { fileURLToPath } from 'url';
import webpack, { type Configuration } from 'webpack';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isDev = process.env.NODE_ENV === 'development';
const config: Configuration = {
mode: isDev ? 'development' : 'production',
entry: {
// popup: './src/pages/Popup.tsx',
options: {
import: './src/pages/Options.tsx',
filename: 'options.js',
},
'service-worker': './src/pages/ServiceWorker.ts',
offscreen: './src/pages/Offscreen.ts',
},
output: {
publicPath: '',
path: path.resolve(__dirname, isDev ? 'dist/dev' : 'dist/prod'),
filename: '[name].js',
clean: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
config: path.resolve(__dirname, 'postcss.config.js'),
},
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
plugins: [
new MiniCssExtractPlugin({
filename: 'globals.css',
}),
// new HtmlWebpackPlugin({
// template: './public/popup.html',
// filename: 'popup.html',
// chunks: ['popup'],
// }),
new HtmlWebpackPlugin({
template: './public/options.html',
filename: 'options.html',
chunks: ['options'],
}),
new HtmlWebpackPlugin({
template: './public/offscreen.html',
filename: 'offscreen.html',
chunks: ['offscreen'],
}),
new CopyPlugin({
patterns: [
{
from: 'public',
to: '.',
globOptions: {
ignore: ['**/*.sketch', '**/*.html', '**/.DS_Store'],
},
},
{ from: 'manifest.json', to: '.' },
],
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
],
// devtool: isDev ? 'inline-source-map' : false,
devtool: isDev ? 'source-map' : false,
optimization: {
minimize: !isDev,
},
};
export default config;