-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
85 lines (82 loc) · 2.46 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
import template from 'lodash/template';
import {readFileSync} from 'fs';
import {join, resolve} from 'path';
import {BannerPlugin, Configuration} from 'webpack';
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const pkg: {name: string} = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));
const banner: string = template(readFileSync(join(__dirname, 'LICENSE_BANNER'), 'utf8'))({
pkg,
date: new Date()
});
const baseConfiguration: Partial<Configuration> = {
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
resolve: {
extensions: ['.ts', '.js'],
},
plugins: [
new BannerPlugin({banner, raw: true}),
new CleanWebpackPlugin({cleanOnceBeforeBuildPatterns: []}),
new ForkTsCheckerWebpackPlugin({eslint: {files: './{lib,benchmark,debug}/**/*.{ts,tsx,js,jsx}'}})
],
output: {
filename: '[name].js',
libraryTarget: 'umd',
devtoolModuleFilenameTemplate: `webpack:///${pkg.name}/[resource-path]`
}
};
export default [
{
...baseConfiguration,
name: 'dist',
mode: 'production',
devtool: 'source-map',
entry: {
sort: resolve(__dirname, './index.ts')
}
},
{
...baseConfiguration,
name: 'karma',
mode: 'development',
devtool: 'inline-source-map',
module: {
...baseConfiguration.module,
rules: [
...baseConfiguration.module.rules,
{
test: /\.(js|ts)$/,
exclude: /(node_modules|\.spec\.(js|ts)$)/,
loader: 'istanbul-instrumenter-loader',
enforce: 'post',
options: {esModules: true}
}
]
}
},
{
...baseConfiguration,
name: 'debug',
mode: 'development',
devtool: 'inline-source-map',
entry: {
[pkg.name]: resolve(__dirname, './debug/index.js')
},
plugins: [
...baseConfiguration.plugins,
new HtmlWebpackPlugin({
title: 'Debug',
template: resolve(__dirname, './debug/index.ejs')
})
]
}
] as Configuration[];