-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
97 lines (89 loc) · 2.36 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
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
var nodeExternals = require('webpack-node-externals');
var path = require('path');
var fs = require('fs');
module.exports = {
entry: './index.ts',
mode: 'production',
externals: [nodeExternals()],
context: path.resolve(__dirname, 'src'),
output: {
filename: 'jarvanscript.js',
path: path.resolve(__dirname, 'lib'),
libraryTarget: 'commonjs',
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader'
}
}
]
},
resolve: {
extensions: [".js", ".ts"]
},
plugins: [
new DtsBundlePlugin({
in: './src',
out: './dist',
dts: {
main: path.resolve(__dirname, 'dist/**/*.d.ts'),
out: path.resolve(__dirname, 'lib/jarvanscript.d.ts'),
exclude: function(file) {
return (
/classes\/enums\/methods\.d\.ts/.test(file) ||
/classes\/interfaces\.d\.ts/.test(file) ||
/classes\/interfaces\/index/.test(file) ||
/classes\/enums\.d\.ts/.test(file) ||
/classes\/enums\/index/.test(file) ||
/classes\/managers/.test(file) ||
/classes\/dto/.test(file) ||
/wrappers/.test(file) ||
/handlers/.test(file)
)
}
},
}),
]
};
function DtsBundlePlugin(config) {
this.config = config
}
DtsBundlePlugin.prototype.apply = function (compiler) {
var _this = this
compiler.plugin('done', function() {
var dts = require('dts-bundle');
walkSync(_this.config.in).filter(function (file) {
return file.endsWith('.d.ts')
}).forEach(function(file) {
var contents = fs.readFileSync(file)
var outFile = file.replace(path.join(_this.config.in), path.join(_this.config.out))
fs.writeFileSync(
outFile,
contents,
)
})
dts.bundle(Object.assign({}, {
name: 'jarvanscript',
outputAsModuleFolder: true
}, _this.config.dts))
});
};
function walkSync(dir, filelist) {
var path = path || require('path');
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = walkSync(path.join(dir, file), filelist);
}
else {
filelist.push(path.join(dir, file));
}
});
return filelist;
};