-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
152 lines (147 loc) · 4.73 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
const path = require('path');
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const packageJson = require('./package.json');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const JsonMinimizerPlugin = require("json-minimizer-webpack-plugin");
const fs = require('fs');
const ESLintPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = (env, argv) => {
const isProduction = env.prod === true;
const isDevelopment = !isProduction;
const config = {
mode: isProduction ? 'production' : 'development',
entry: {
popup: './src/popup/popup.js',
"bandcamp.content": './src/bandcamp/content.js',
"bandcamp.inject": './src/bandcamp/inject.js',
"discogs.draft": './src/discogs/draft.js',
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]',
},
},
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true
}
},
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
},
{
test: /\.js$/,
loader: "source-map-loader",
include: path.resolve(__dirname, 'src'),
},
{
test: /\.json$/i,
type: "asset/resource",
},
],
},
optimization: {
minimize: isProduction,
minimizer: [
new CssMinimizerPlugin(),
new JsonMinimizerPlugin(),
new TerserPlugin()
],
},
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
},
plugins: [
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new ESLintPlugin({
configType: 'flat',
fix: true
}),
new HtmlWebpackPlugin({
template: "./src/popup/popup.ejs",
filename: "popup.html",
templateParameters: {
tabContentBandcamp: fs.readFileSync('./src/popup/content/bandcamp.html', 'utf-8'),
tabContentReleaseCard: fs.readFileSync('./src/popup/content/release-card_tab.html', 'utf-8'),
tabContentReleases: fs.readFileSync('./src/popup/content/releases_tab.html', 'utf-8'),
tabContentHistory: fs.readFileSync('./src/popup/content/history_tab.html', 'utf-8'),
tabContentAbout: fs.readFileSync('./src/popup/content/about.html', 'utf-8'),
bcDataNotProvided: fs.readFileSync('./src/popup/content/messages/bcDataNotProvided.html', 'utf-8'),
templates: [
fs.readFileSync('./src/popup/content/release-card-template.html', 'utf-8'),
]
},
minify: true,
// Entry point scripts
chunks: ["popup"]
}),
new CopyPlugin({
patterns: [
{
from: "src/manifest.json",
to: path.join(__dirname, "dist"),
force: true,
transform: function (content, path) {
let manifest = JSON.parse(content.toString());
manifest.version = packageJson.version;
if (isDevelopment) {
// version: MMDD.HHMMSS
const version = new Date().toISOString().slice(5, 19).replace(/[-:T]/g, '').replace(/(.{4})(.{6})/, '$1.$2');
manifest.name += ` [Dev ${version}]`;
console.log("\n\nManifest name:", manifest.name, "\n");
}
return Buffer.from(JSON.stringify(manifest, null, "\t"));
},
},
{
from: "images/**",
to: path.join(__dirname, "dist"),
force: true,
},
{
from: "src/data/discogs_genres.json",
to: path.join(__dirname, "dist/data"),
force: true,
},
{
from: "src/data/keyword_mapping.json",
to: path.join(__dirname, "dist/data"),
force: true,
},
],
}),
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
devtool: isDevelopment ? 'inline-source-map' : 'source-map',
devServer: {
static: isDevelopment ? './dist' : { directory: path.resolve(__dirname, 'dist') },
devMiddleware: {
writeToDisk: true,
},
hot: false,
},
};
return config;
};