-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.ts
79 lines (76 loc) · 1.94 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
import path from 'path';
import pack from './package.json';
import CopyPlugin from 'copy-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import { type Configuration, DefinePlugin } from 'webpack';
const isProduction = process.env.NODE_ENV === 'production';
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: /\.(svg|njk|html)$/,
type: 'asset/source',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|gif)$/i,
type: 'asset/inline',
},
],
},
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),
}),
],
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.tsx', '.js'],
mainFields: ['browser', 'module', 'main'],
},
externals: {
obsidian: 'commonjs2 obsidian',
'@codemirror/view': 'commonjs2 @codemirror/view',
'@codemirror/state': 'commonjs2 @codemirror/state',
'@codemirror/rangeset': 'commonjs2 @codemirror/rangeset',
'webworker-threads': 'require(webworker-threads)',
},
};
export default config;