This repository has been archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.ts
99 lines (92 loc) · 2.29 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
93
94
95
96
97
98
99
import CleanWebpackPlugin from 'clean-webpack-plugin'
import * as dts from 'dts-bundle'
import * as fs from 'fs'
import * as path from 'path'
import * as prettier from 'prettier'
import UglifyJsPlugin from 'uglifyjs-webpack-plugin'
import * as webpack from 'webpack'
class DtsBundlePlugin implements webpack.Plugin {
public apply (compiler: any): void {
compiler.hooks.done.tap('DtsBundlePlugin', () => {
// let dts = require('dts-bundle')
dts.bundle({
name: 'moment',
main: 'dist/types/index.d.ts',
out: '../moment-recur-ts.d.ts',
removeSource: true
// outputAsModuleFolder: true
})
fs.rmdirSync(path.resolve(__dirname, './dist/types'))
const filename = path.resolve(__dirname, './dist/moment-recur-ts.d.ts')
fs.writeFileSync(filename, prettier.format(
fs.readFileSync(filename, 'utf8'),
{
filepath: filename,
semi: false,
singleQuote: true
}
).replace('moment/index//moment', 'moment'))
})
}
}
const config: webpack.Configuration = {
mode: 'production',
entry: {
'moment-recur-ts': './src/index.ts',
'moment-recur-ts.min': './src/index.ts'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
libraryTarget: 'umd',
library: 'moment-recur-ts',
umdNamedDefine: true
},
resolve: {
extensions: ['.ts', '.js']
},
externals: {
moment: 'moment'
},
devtool: 'source-map',
// optimization: {
// minimize: true
// },
optimization: {
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
include: /\.min\.js$/
})
]
},
plugins: [
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
// include: /\.min\.js$/
// }),
// new DeclarationBundlerPlugin({
// moduleName: 'moment',
// out: 'moment-recur-ts.d.ts'
// }),
new DtsBundlePlugin(),
new CleanWebpackPlugin(['./dist'], {
allowExternal: true
})
],
module: {
rules: [{
test: /\.ts$/,
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
compilerOptions: {
// outDir: 'es',
declarationDir: 'types'
}
}
// exclude: /node_modules/,
}]
}
}
export default config