forked from hadynz/obsidian-kindle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
92 lines (88 loc) · 2.26 KB
/
webpack.config.ts
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
import path from 'path';
import pack from './package.json';
import sveltePreprocess from 'svelte-preprocess';
import CopyPlugin from 'copy-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import SentryWebpackPlugin from '@sentry/webpack-plugin';
import { Configuration, DefinePlugin } from 'webpack';
const isProduction = process.env.NODE_ENV === 'production';
const sentryPlugin = new SentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'hadynz',
project: 'kindle-highlights',
release: pack.version,
ignore: ['node_modules', 'webpack.config.js'],
include: 'dist',
});
const config: Configuration = {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs',
clean: true,
},
target: 'node',
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'source-map' : 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
{
test: /\.(svelte)$/,
use: [
{
loader: 'svelte-loader',
options: {
preprocess: sveltePreprocess({}),
},
},
],
},
{
test: /\.(svg|njk|html)$/,
type: 'asset/source',
},
],
},
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
extractComments: false,
minify: TerserPlugin.uglifyJsMinify,
terserOptions: {},
}),
],
},
plugins: [
new CopyPlugin({
patterns: [{ from: './manifest.json', to: '.' }],
}),
new DefinePlugin({
PACKAGE_NAME: JSON.stringify(pack.name),
VERSION: JSON.stringify(pack.version),
PRODUCTION: JSON.stringify(isProduction),
}),
...(isProduction ? [sentryPlugin] : []),
],
resolve: {
alias: {
svelte: path.resolve('node_modules', 'svelte'),
'~': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.tsx', '.js', '.svelte'],
mainFields: ['svelte', 'browser', 'module', 'main'],
},
externals: {
electron: 'commonjs2 electron',
obsidian: 'commonjs2 obsidian',
},
};
export default config;