-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
62 lines (59 loc) · 1.35 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
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
// Build dependencies are ok as devDependencies
// eslint-disable-next-line import/no-extraneous-dependencies
import TerserPlugin from 'terser-webpack-plugin';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const mode = process.argv.includes('--mode=production')
? 'production'
: 'development';
const libraryName = process.env.npm_package_name;
const isProd = mode === 'production';
export default {
mode,
optimization: {
minimize: isProd,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
},
entry: {
dist: `./${libraryName}.ts`,
},
output: {
filename: `${libraryName}.js`,
path: resolve(__dirname, 'dist'),
clean: true,
},
target: ['browserslist'],
module: {
rules: [
{
test: /\.ts?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
{
loader: 'ts-loader',
},
],
exclude: /node_modules/,
},
],
},
stats: {
colors: true,
},
devtool: isProd ? undefined : 'eval-cheap-module-source-map',
};